sunny012097
asked on
Thread scheduling
how can i control execution of multiple threads in a sequence?
thread1 > thread2 > thread3 > thread1 ......
i thought about writing a schedular but when i wrote it i had problems about switching because the threads scheduled can also have their own sleep or wait conditions.
is there any robust solution for this kind of things?
thread1 > thread2 > thread3 > thread1 ......
i thought about writing a schedular but when i wrote it i had problems about switching because the threads scheduled can also have their own sleep or wait conditions.
is there any robust solution for this kind of things?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Hello
well u can try setting the priority of each thread which might just help you out
Thread.setPriority(int );
Thread.MIN_PRIORITY;
Thread.NORM_PRIORITY;
Thread.MAX_PRIORITY;
or u could also try synchronizing the threads.
well u can try setting the priority of each thread which might just help you out
Thread.setPriority(int );
Thread.MIN_PRIORITY;
Thread.NORM_PRIORITY;
Thread.MAX_PRIORITY;
or u could also try synchronizing the threads.
Don't fumble with priorities! Follow objects' advise thats the perfect answer!
;JOOP!
;JOOP!
Some thing funny...
Have an instance of a class(WhoNext) which here contains a whoNext boolean array....
If Thread 1 is using then make WhoNext.whoNext[1] = 1(my turn) and rest all to 0.
If Thread 1 is done and Thread 2 should be executed..... say
WhoNext.whoNext[1] = 0(Not My turn)
WhoNext.whoNext[2] = 1(My Turn)
Say For Example Thread 1 is supposed to run but do not get CPU time then as its not other turn to run their job they should just say
Thread.yield();
:-)
Have an instance of a class(WhoNext) which here contains a whoNext boolean array....
If Thread 1 is using then make WhoNext.whoNext[1] = 1(my turn) and rest all to 0.
If Thread 1 is done and Thread 2 should be executed..... say
WhoNext.whoNext[1] = 0(Not My turn)
WhoNext.whoNext[2] = 1(My Turn)
Say For Example Thread 1 is supposed to run but do not get CPU time then as its not other turn to run their job they should just say
Thread.yield();
:-)
No, just call:
thread1.run();
thread2.run();
.....
;JOOP!
thread1.run();
thread2.run();
.....
;JOOP!
Then you are not using the concept of Threads all you are doing is making some function calls.....
which would be executing sequentially........
which would be executing sequentially........
That's exactly right: threads in a sequence ARE NOT THREADS ANYMORE!
;JOOP!
;JOOP!
ASKER
i am talking about squentially runing threads like;
thread 1
thread 2
thread 3
thread 1
thread 2
...
thread 1
thread 2
thread 3
thread 1
thread 2
...
Threads are subprocesses that run concurrently.
If you want it like you describe, you don't need a single thread, unless you want to run them
concurrently to your main.
Then you only need ONE thread that calls these 3 procedures in sequence.
;JOOP!
If you want it like you describe, you don't need a single thread, unless you want to run them
concurrently to your main.
Then you only need ONE thread that calls these 3 procedures in sequence.
;JOOP!
yaaa JOOP you were right
if they are seperate threads, then either don't start the next thread until the previous is finished, or call join() on the previous at the start of each thread to wait until it completes.