私は次のように何かをしようとしています -
- スレッドが作成されます
- 新しいスレッドが作成されると、前のスレッドの変数が更新されます
limit
- 進行状況は 3 番目のスレッドで繰り返されます。つまり、このスレッド
limit
はスレッド ID1 と ID2 の変数を更新します。
ここにいくつかのサンプルコードがあります
メインクラス
public class TaskImplementer {
public static int End;
public static int threadCount = 5;
public static void main(String[] args) {
int i=0;
findEnd();
while (i < threadCount) {
if(isPossible()) { // check for some condition
createThread aThread = new createThread(i, End);
aThread.start();
}
i++;
//updateGUI(); //updateGUI - show working Threads
}
}
private static void findEnd() {
//updates End variable
}
private static boolean isPossible() {
//.....
//Check for a condition
return false;
}
}
createThread クラス
public class createThread extends Thread {
private static int ID;
private static int limit;
private static int startfromSomething;
public createThread(int ThreadID, int End) {
ID = ThreadID;
limit = End;
}
private void doSomething() {
//does work
}
@Override
public void run() {
while(startfromSomething < limit) {
doSomething();
}
TaskImplementer.i--;
}
}
変数limit
は、正常に作成された各スレッドによって更新される必要があります。可能ですか、何か提案してください。前もって感謝します。