我试图通过放置以下内容来增加应用程序中线程的优先级:
Thread.currentThread().setPriority(N);
当前线程的正常优先级是 5,我可以更改N为低至 1,但如果我将其设置为 0 或 -1,我会在手机上收到强制关闭消息。
我不能增加这个线程的优先级有什么原因吗?
我试图通过放置以下内容来增加应用程序中线程的优先级:
Thread.currentThread().setPriority(N);
当前线程的正常优先级是 5,我可以更改N为低至 1,但如果我将其设置为 0 或 -1,我会在手机上收到强制关闭消息。
我不能增加这个线程的优先级有什么原因吗?
If you look at the documentation for Thread.setPriority(), it says the priority must be in a range defined by MAX_PRIORITY (10) and MIN_PRIORITY (1). Since 0 and -1 are outside that range you should be seeing an IllegalArgumentException.