How to stop a thread waiting in a blocking read operation in Java?

后端 未结 7 1902
萌比男神i
萌比男神i 2020-12-03 10:40

I have a thread that executes the following code:

public void run() {
    try {
        int n = 0;
        byte[] buffer = new byte[4096];
        while ((n          


        
7条回答
  •  失恋的感觉
    2020-12-03 10:54

    You've stumbled upon a 9 year old bug no one is willing to fix. They say there are some workarounds in this bug report. Most probably, you'll need to find some other way to set timeout (busy waiting seems unavoidable).

提交回复
热议问题