The code snippet below is开发者_C百科 in my JUnit Test Case class. I am using three threads to test a class called SharedResources; getGuy is just one of them. My problem is after starting the threads, only the first one reads the sharedResource, and that only once.
Thread getGuy = new Thread(new Runnable() {
public void run() {
for(int i=0; i < 5; i++) {
try {
Thread.sleep(500);
} catch (InterruptedException e) {
e.printStackTrace();
}
System.out.println("I consume",resource.get());
}//for
}
});
Thanks for any help.
This is a basic producer-consumer design. Instead of creating producer and consumer classes, I simply create the sharedResource class. Then in the JUnit Test Case, I create the producer and consumer Threads. getGuy is a consumer thread.
Thanks
精彩评论