Solved

Thread scheduling

Posted on 2004-10-08
12
229 Views
Last Modified: 2008-03-06
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?
0
Comment
Question by:sunny012097
  • 4
  • 3
  • 2
  • +3
12 Comments
 
LVL 5

Accepted Solution

by:
Naeemg earned 500 total points
ID: 12256612
0
 
LVL 92

Expert Comment

by:objects
ID: 12256617
if u want them to run consecutely then why run them in seperate threads, just call them consecutively from the one thread.

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.
0
 
LVL 5

Expert Comment

by:Naeemg
ID: 12256619
0
 
LVL 15

Expert Comment

by:babuno5
ID: 12256942
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.
0
 
LVL 24

Expert Comment

by:sciuriware
ID: 12258301
Don't fumble with priorities! Follow objects' advise thats the perfect answer!

;JOOP!
0
 
LVL 2

Expert Comment

by:ThummalaRaghuveer
ID: 12261895
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();

:-)
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 24

Expert Comment

by:sciuriware
ID: 12265314
No, just call:

      thread1.run();
      thread2.run();
.....
;JOOP!
0
 
LVL 2

Expert Comment

by:ThummalaRaghuveer
ID: 12266653
Then you are not using the concept of Threads all you are doing is making some function calls.....

which would be executing sequentially........
0
 
LVL 24

Expert Comment

by:sciuriware
ID: 12266857
That's exactly right: threads in a sequence ARE NOT THREADS ANYMORE!

;JOOP!
0
 

Author Comment

by:sunny012097
ID: 12267088
i am talking about squentially runing threads like;

              thread 1
              thread 2
              thread 3
              thread 1
              thread 2
              ...
0
 
LVL 24

Expert Comment

by:sciuriware
ID: 12267108
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!
0
 
LVL 2

Expert Comment

by:ThummalaRaghuveer
ID: 12267461
yaaa JOOP you were right
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

863 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now