java队列多线程

java队列多线程
我编了一个多线程程序,但出现了一些问题请高手帮忙修改一下,主要显示这个内容System.out.print(duilie.theQueue.remove()); System.out.println("号请到第1窗口");
但请不要改变我的类,因为我在别的地方还需要,只改变类里的代码,谢谢了,坐等!
import java.lang.Thread;
import java.io.*;
import java.util.Scanner;

public class paidui {

/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
int hao=1;

Thread t1=new runner1();
t1.run();
System.out.print("这里是主线程");
}

}

class runner1 extends Thread{
public void run(){
//duilie d=new duilie();
while(true){
if(duilie.theQueue.isEmpty()){
}
else{
System.out.print(duilie.theQueue.remove());
System.out.println("号请到第1窗口");
try{
Thread.sleep(10000);
}catch(InterruptedException e){};
}
}

}
}
class duilie {
static Queue theQueue= new Queue(100);

public duilie(){ }
}
public class Queue
{
private int maxSize;
private int[] queArray;
private int front;
private int rear;
private int nItems;

// --------------------------------------------------------------
public Queue(int s) // constructor
{
maxSize = s;
queArray = new int[maxSize];
front = 0;
rear = -1;
nItems = 0;
}
// --------------------------------------------------------------
public synchronized void insert(int j) // put item at rear of queue
{
if(rear == maxSize-1) // deal with wraparound
rear = -1;
queArray[++rear] = j; // increment rear and insert
nItems++; // one more item
}
// --------------------------------------------------------------
public synchronized int remove() // take item from front of queue
{
int temp = queArray[front++]; // get value and incr front
if(front == maxSize) // deal with wraparound
front = 0;
nItems--; // one less item
return temp;
}
// --------------------------------------------------------------
public int peekFront() // peek at front of queue
{
return queArray[front];
}
// --------------------------------------------------------------
public boolean isEmpty() // true if queue is empty
{
return (nItems==0);
}
// --------------------------------------------------------------
public boolean isFull() // true if queue is full
{
return (nItems==maxSize);
}
// --------------------------------------------------------------
public int size() // number of items in queue
{
return nItems;
}
// --------------------------------------------------------------
} // end class Queue
t1.run();
改成t1.start();试一下。
← 上一篇: 下一篇: →