Today, I tried to wirte some code to test thread.
Use a Schedular to controll thread's running.
For thread:
public class ControllerThread extends Thread {
public void run() {
...
Schedular.waitForOthers(this);
...
}
}
In Schedular
public class Schedular {
public static synchronized void waitForOthers(ControllerThread thread) throws InterruptedException {
waitingThreadNum++; // waitingThreadNum is a counter.
if (waitingThreadNum != threads.size()) {
System.out.println("Thread:" + thread.getName() + " is going to wait");
wait(); // thread.wait() is useless here
} else {
waitingThreadNum = 0;
System.out.println("All threads will run");
notifyAll();
}
}
}
Is there anybody know why thread.wait cannot work in Schedular?
It is very hard for me to start a blog.
Firstly it is I'm lack of permanence. My interests are always chaging, I cannot focus on one thing for a long time, especially in network. Once I have a blog in campus bbs, but I spent so little time on it that there are only two senseless articles.
Secondly my work time is very long. I have to work from 8:30a.m to nearly 9:00p.m everyday. Duration this time, it is forbidden to access blog. So I don't think that I can pay too much attention on my own area.
When I work on protype type for next project these days, I try hard to avoid old detects that appear in the previous prooject. Unfortunately, I only know what is bad, which is not enough. Though I have thought much, the design is not satisfied. Some workmates said it is only my dream.
I look for the answers in the net, and find some good ideas. At this time , I appreciate others' knowledge sharing. And I think I also need to share my exceprience and discuss with others.
So I start this blog. Hope it is a new start.