Discussion on java multithreaded join method and priority method

  • 2020-05-30 20:18:28
  • OfStack

join:

When the A thread executes the.join () method of the B thread, A waits. A will not execute until all the B threads have executed.

join can be used to temporarily join thread execution.

1. When a thread USES the join method, the main thread stops and waits for it to finish executing. If the thread freezes, the main thread dies

2. When two or more threads are turned on, the A thread will not use join method until the main thread stops. The threads will alternate until A has finished executing

1. tostring (), method, gets the thread specific name, priority

2. Priority represents the frequency of resource grabs

3. The three levels 1-5-10 are set in java. Since they are fixed values, they are capitalized

4. Just like setting background thread 1, all functions belong to thread, and r.setPriority (Thread.letter level) is directly called by thread object.

5. Anonymous inner classes? Is the key to multithreading, must master


class Demo implements Runnable
{
  public void run()
  {
    for(int x=0; x<70; x++)
    {
      System.out.println(Thread.currentThread().toString()+"....."+x);
      Thread.yield();
    }
  }
}


class JoinDemo
{
  public static void main(String[] args) throws Exception
  {
    Demo d = new Demo();
    Thread t1 = new Thread(d);
    Thread t2 = new Thread(d);
    t1.start();
    
    //t1.setPriority(Thread.MAX_PRIORITY);

    t2.start();

    //t1.join();

    for(int x=0; x<80; x++)
    {
      //System.out.println("main....."+x);
    }
    System.out.println("over");
  }
}


Related articles: