Setting priority to Java's threads

前端 未结 5 2085
没有蜡笔的小新
没有蜡笔的小新 2020-11-27 20:14

I have a program that runs in a few threads. The main thread shares an object with the other threads and in the main I have a call to:

synchronized(obj){
            


        
5条回答
  •  被撕碎了的回忆
    2020-11-27 20:52

    As others already answered, you can indeed set a priority to a thread as follows:

    Thread.currentThread().setPriority(priority);
    

    But please be aware, in your example, that thread priority has nothing to do in which order threads get access to a synchronized object. Java uses other criteria to give access. See for example this.

提交回复
热议问题