以下のコードでは、スレッド t1 で Runnable の生成を実行し、スレッド 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();
}
}