在下面的代码中,我希望 Thread t1 执行 Runnable 的产生,而 Thread t2 执行 Runnable 的消耗。这行得通吗?
class Processor implements Runnable {
@override
run(){
produce();
consume();
}
void produce(){
// code to produce, synchronize
}
void consume(){
// code to consume, synchronize
}
}
Class App {
public static void main(String[] args){
Processor p = new Processor()
Thread t1 = new Thread(p);
t1.start();
Thread t2 = new Thread(p);
t2.start();
}
}