Results 1 to 6 of 6

Thread: Thread scheduling In Java

  1. #1
    Join Date
    Nov 2009
    Posts
    678

    Thread scheduling In Java

    Hello, I am learning java programming language. And while learning it, I am quiet confused about the Thread scheduling. I have read different articles and programs related to it, but it is not possible for me to get knowledge about it and so if you are having details about the Thread Scheduling in Java then please provide that to me if it is in simple format. Thank you in advance.

  2. #2
    Join Date
    May 2008
    Posts
    2,012

    Re: Thread scheduling In Java

    Thread scheduling in java contains different criteria as below:
    • Priority
    • Quantum
    • State
    • Metrics


    If you consider the Criteria of the Priority then it will come up with following type:
    • higher priority
    • equal priority

  3. #3
    Join Date
    Apr 2008
    Posts
    2,005

    Re: Thread scheduling In Java

    Hello, if you are thinking to make use of the Thread scheduling in java, then it will provide you the features below:
    • The Java virtual Machine for thread scheduling makes use of the preemptive , priority based algorithm.
    • Your each and every thread will be run by java virtual machine with the higher priority order. The thread which is having more priority will be run by it.
    • But, now consider that there are two threads available which are having same priority then it will simply make use of the FIFO Algorithm and solve the problem.

  4. #4
    Join Date
    May 2008
    Posts
    2,297

    Re: Thread scheduling In Java

    Hello, I am not having more information about the Thread scheduling in java, but I am having the code below which will help you to get knowledge about it.
    Code:
    public class ThreadTest 
    {
    public static void main(String[] args) 
    {
    int Total = Integer.parseInt(args[0]);
    long Num = Long.parseLong(args[1]);
    Thread thread[] = new Thread[Total];
    for (int i = 0; i < t.length; i++) 
    {
    thread[i] = new Thread(new Task(Num, "Task " + i));
    thread[i].start( );
    }
    for (int i = 0; i < t.length; i++) 
    {
    try 
    {
    thread[i].join( );
    } 
    catch (InterruptedException ie) 
    {
    }
    }
    }
    
    }

  5. #5
    Join Date
    Oct 2005
    Posts
    2,393

    Re: Thread scheduling In Java

    Hello, I have got the code below which will simply provide you details about the treadscheduling in java:
    Code:
    public class TaskExecutorExample 
    {
     private class MSGPrinterTask implements Runnable 
    {
       private String str;
        public MSGPrinterTask(String str) 
    {
          this.str = str;
        }
        public void run() 
    {
          System.out.println(str);
        }
      }
      private TaskExecutor Texecute;
      public TaskExecutorExample(TaskExecutor Texecute) 
    {
        this.Texecute = Texecute;
      }
    
      public void printMSGs() 
    {
        for(int i = 0; i < 25; i++) 
    {
          Texecute.execute(new MSGPrinterTask("MSG" + i));
        }
      }
    And for getting Thread Scheduling Visualizer 2.0 you can click on the link below:

    Thread Scheduling Visualizer 2.0

  6. #6
    Join Date
    Apr 2008
    Posts
    1,948

    Re: Thread scheduling In Java

    Hello, if you make use of the code below then you will simply able to understand the concept of the Thread Scheduling in java. It is really easy to understand:
    Code:
    public class ThreaSTest extends Thread
    {
    public ThreaSTest(){
    TimeValue = DEFAULT_TIME_SLICE;
    Line = new Circularlist();
    }
    public ThreaSTest(int quantum){
    TimeValue = quantum;
    Line = new Circularlist();
    }
    public addThread(Thread t) {
    t.setPriority(3);
    Line.additem(t);
    }
    private void schedulerSleep() {
    try{
    Thread.sleep(TimeValue );
    } catch (InterruptedException e){};
    }
    public void run(){
    Thread current;
    This.setpriority(6);
    While (true) {
    current = (Thread)qeue.getnext();
    if ( (current != null) && (current.isAlive()) ){
    current.setPriority(4);
    schedulerSleep();
    current.setPriority(3)
    }
    }
    }
    private CircularList Line;
    private int TimeValue;
    private static final int DEFAULT_TIME_SLICE = 10000;
    }
    public class TesThreaSTest
    {
    public static void main()String args[]) {
    Thread.currentThread().setpriority(Thread.Max_Priority);
    Schedular CPUSchedular = new ThreaSTest ();
    CPUSchedular.start()
    TestThread Test1 = new TestThread("Thread 1");
    Test1.start()
    CpuSchedular.addThread(Test1);
    TestThread Test3 = new TestThread("Thread 3");
    Test3.start()
    CpuSchedular.addThread(Test3);
    TestThread Test3 = new TestThread("Thread 1");
    Test3.start()
    CpuSchedular.addThread(Test3);
    }
    }

Similar Threads

  1. Synchronize a producer thread and a consumer thread in C#
    By Ayuka in forum Software Development
    Replies: 6
    Last Post: 10-11-2010, 04:04 AM
  2. Control thread speed in java
    By Gunner 1 in forum Software Development
    Replies: 5
    Last Post: 14-02-2010, 05:29 AM
  3. What is the Event Dispatch Thread in Java?
    By Flaco in forum Software Development
    Replies: 5
    Last Post: 14-02-2010, 05:28 AM
  4. Thread Priorities in java
    By Aakarshan.d in forum Software Development
    Replies: 3
    Last Post: 08-12-2009, 02:02 PM
  5. Task Scheduling in JAVA
    By Jagdish Gada in forum Software Development
    Replies: 5
    Last Post: 30-11-2009, 09:45 AM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,711,702,739.79051 seconds with 17 queries