📄 2.java
字号:
import java.util.*;
public class Test_thread
{
}
class Node
{
Cpu_thread data=new Cpu_thread();
Node next;
}
class Queue
{
Node font=new Node();
Node rear=font;
public void enqueue(Cpu_thread e)
{
this.rear.data=e;
this.rear=this.rear.next=new Node();
}
public Cpu_thread dequeue()
{
if(this.font==this.rear)
{
System.out.print("queue is empty!");
System.exit(0);
Cpu_thread re_thread=new Cpu_thread();
return re_thread;
}
Node temp=this.font;
this.font=this.font.next;
Cpu_thread e=temp.data;
temp=null;
return e;
}
}
class Cpu_thread
{
String name="";
int time=0;
Date nowtime=new Date();
static Queue q=new Queue();
Cpu_thread()
{}
Cpu_thread(String name)
{
this.time=this.nowtime.getSeconds();
this.name=name;
q.enqueue(this);
}
public void start()
{
Cpu_thread t=q.dequeue();
t.run(t);
}
public void run(Cpu_thread t)
{
System.out.println();
System.out.print("thread "+t.name+" run:");
int i=655;
int j=10;
int count=0;
while(j--!=0&&count<=100)
{
while(i--!=0&&count++<=100)
{
if(i==621)
{
this.sleep(t);
}
System.out.print("\t"+i);
}
System.out.println();
}
}
public void sleep(Cpu_thread sleep_t)
{
q.enqueue(sleep_t);
while(true)
{
if(q.font.data==sleep_t) return;
Cpu_thread t=q.dequeue();
t.run(t);
}
}
}
class mainclass
{
public static void main(String args[])
{
Cpu_thread t1=new Cpu_thread("1");
Cpu_thread t2=new Cpu_thread("2");
t1.start();
t2.start();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -