【问题标题】:How to cancel a thread making a http request from another thread如何取消从另一个线程发出http请求的线程
【发布时间】:2017-12-19 16:50:33
【问题描述】:

关于我们如何杀死发出 http post 请求并等待得到响应的线程的任何建议。我想从另一个并行运行的线程中杀死这个线程,然后它才能收到来自请求的任何响应。我得到了关闭或中止 http post 请求的建议,但没有锻炼,谁能建议我们如何在这种情况下中止 http 请求或任何其他方式来实现这一点。

【问题讨论】:

  • 试试Thread.interrupt
  • 停止线程的唯一方法是中断它。线程的 run 方法要么会正确响应中断,要么不会。如果没有,您将无能为力。
  • stackoverflow.com/questions/3000214/…。你也看过异步 http 吗?
  • 提供更多详细信息,您使用的是什么 http 客户端。你使用第三方库吗? (例如 Apache HTTP 客户端)这一切都取决于你如何做。我猜在大多数情况下中断线程会很麻烦。我建议您阅读您使用的客户端的文档。

标签: java multithreading http


【解决方案1】:

发出请求的线程在等待服务器响应时被阻塞。如果您进行线程转储并查看,它将在一些 read() 方法中,但不在 Thread.sleep 中。所以调用 interrupt() 不会有效果(除非它是一个 InterruptibleChannel)。 您是否有权访问发出 POST 请求的套接字或输出流?如果是这样,您可以关闭它,这将导致读取等待出现异常。 有可以放的代码示例吗?

【讨论】:

  • 你是对的,如果我们在等待响应期间对线程执行 thread.getState(),我们将获得 RUNNING 状态。因此,当触发中断时,线程的中断标志被设置,但线程将在完成请求后被优雅地杀死。
  • 我正在使用 apache http 客户端,但我无法使用 asynchttp。我尝试请求
  • 我正在使用 apache http 客户端,但我无法使用 asynchttp。我尝试使用一个线程发送请求和 ex:ReqThread 并取消侦听器线程 ex:CancelThread 并且我有一个共享变量对象保存 httpPost 对象。实际请求发生在 A 类中,它使用 ReqThread 发送的 httpPost 发送请求。我在 CancelThread 中有取消事件侦听实现,它读取由 ReqThreaad 在共享对象中设置的 httpPost 以发出 httppost.abort()。这是我将 httpPost 对象设为 null 的问题。
【解决方案2】:

大家好,终于实现了这个关闭套接字的想法并开始工作了。下面是我试过的sn-p。

我的请求线程

package com.pkg.myhttptest;

import org.apache.http.client.methods.HttpPost;

public class RequestThread implements Runnable{

    Message msg = null;
    Util util = null;
    public RequestThread(Message msg, Util util) {
        this.msg = msg;
        this.util = util;
    }
    public void run() {
        System.out.println("its request thread");
        util.print(msg);
    }



}

取消线程

public class CancelThread implements Runnable {
    Message msg = null;
    Util util = null;
    public CancelThread(Message msg, Util util) {
        this.msg = msg;
        this.util = util;
    }
    public void run() {
        System.out.println("its cancel thread");
        int i=0;
        while(i<5){
            System.out.println("looping" + i);
            i++;
        }
        System.out.println(msg.getHttpost() + "In cancelled");
        Header[] hdr = msg.getHttpost().getAllHeaders();
        System.out.println(hdr.length + "length");
        msg.getHttpost().abort();
        System.out.println(msg.getHttpost().isAborted());

    }

}

共享对象

public class Message {

    HttpPost httpost;

    public HttpPost getHttpost() {
        return httpost;
    }

    public void setHttpost(HttpPost httpost) {
        this.httpost = httpost;
    }
}

实用类

public class Util {
    private final String USER_AGENT = "Mozilla/5.0";

    public void print(Message msg) {
        String url = "https://selfsolve.apple.com/wcResults.do";
        HttpPost post = new HttpPost(url);
        HttpClient client = HttpClientBuilder.create().build(); 
        post.setHeader("User-Agent", USER_AGENT);

        List<NameValuePair> urlParameters = new ArrayList<NameValuePair>();
        urlParameters.add(new BasicNameValuePair("sn", "C02G8416DRJM"));
        urlParameters.add(new BasicNameValuePair("cn", ""));
        urlParameters.add(new BasicNameValuePair("locale", ""));
        urlParameters.add(new BasicNameValuePair("caller", ""));
        urlParameters.add(new BasicNameValuePair("num", "12345"));

        try {
            post.setEntity(new UrlEncodedFormEntity(urlParameters));
            msg.setHttpost(post);
            HttpResponse response = client.execute(post);
            System.out.println("Response Code : " + response.getStatusLine().getStatusCode());

            BufferedReader rd = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));

            StringBuffer result = new StringBuffer();
            String line = "";
            while ((line = rd.readLine()) != null) {
                result.append(line);
            }
        } catch (UnsupportedEncodingException e) {

        } catch (IOException e) {
           e.printStackTrace()
        }
    }

主类

public class App 
{
    public static void main( String[] args )
    {
        Message msg = new Message();
        Util util = new Util();

        Thread reqThread = new Thread(new RequestThread(msg, util));
        Thread cancelThread = new Thread(new CancelThread(msg, util));

        System.out.println("Starting Threads");
        reqThread.start();
        try {
            reqThread.sleep(2000);
            cancelThread.start();
            cancelThread.join();
            System.out.println("closing..");
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
}

我同意它的小未清理代码,但它有效。它会导致以下异常并杀死线程。

java.net.SocketException: Socket is closed
    at java.net.Socket.getInputStream(Socket.java:876)
    at sun.security.ssl.SSLSocketImpl.doneConnect(SSLSocketImpl.java:644)
    at sun.security.ssl.SSLSocketImpl.<init>(SSLSocketImpl.java:549)

感谢所有努力帮助我的人。

【讨论】:

    【解决方案3】:

    我试图解决同样的问题。我写了一个 HTTP Request Runnable,它需要 20 秒超时并在一个线程(第一个线程)上执行。我在一个单独的线程(第二个线程)上写了一个 Timeout Runnable,它应该在 10 秒后中断/停止第一个线程。在主线程中的每一秒(总共 3 个线程),我打印了线程的状态,发现第一个线程一直在运行。

    import java.util.Collections;
    import java.util.LinkedHashMap;
    import java.util.Map;
    import org.apache.http.client.methods.CloseableHttpResponse;
    import org.apache.http.client.methods.HttpGet;
    import org.apache.http.impl.client.DefaultHttpClient;
    import org.apache.http.util.EntityUtils;
    
    public class A_Test_Thread_Interrupt {
        public static final String URL_THAT_CAUSES_CONNECTION_TIMED_OUT_AFTER_20_SECONDS = "https://..."; // Need to provide this for your system.  Must timeout after 20 seconds
    //  java.net.ConnectException: Connection timed out: connect
    //  at java.net.DualStackPlainSocketImpl.connect0(Native Method)
    //  at java.net.DualStackPlainSocketImpl.socketConnect(DualStackPlainSocketImpl.java:79)
    //  at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:350)
    //  at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:206)
    //  at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:188)
    //  at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:172)
    //  at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
    //  at java.net.Socket.connect(Socket.java:589)
    //  at org.apache.http.conn.ssl.SSLSocketFactory.connectSocket(SSLSocketFactory.java:542)
    //  at org.apache.http.conn.ssl.SSLSocketFactory.connectSocket(SSLSocketFactory.java:414)
    //  at org.apache.http.impl.conn.DefaultClientConnectionOperator.openConnection(DefaultClientConnectionOperator.java:180)
    //  at org.apache.http.impl.conn.ManagedClientConnectionImpl.open(ManagedClientConnectionImpl.java:326)
    //  at org.apache.http.impl.client.DefaultRequestDirector.tryConnect(DefaultRequestDirector.java:610)
    //  at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:445)
    //  at org.apache.http.impl.client.AbstractHttpClient.doExecute(AbstractHttpClient.java:835)
    //  at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:83)
    //  at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:108)
    //  at A_Test_Thread_Interrupt$HttpRequestRunnable.run(A_Test_Thread_Interrupt.java:35)
    //  at java.lang.Thread.run(Thread.java:748)
    
        public static void main(String[] args) {
            System.out.println("main Start");
            long startTime = System.currentTimeMillis();
    
            SharedData sd = new SharedData();
    
            System.out.println("Starting HTTPS Request Thread");
            HttpRequestRunnable httpRequestRunnable = new HttpRequestRunnable(sd);
            Thread workerThread = new Thread(httpRequestRunnable);
            workerThread.start();
    
    //      workerThread.stop();
    
            System.out.println("Starting Timeout Thread");
            TimeoutRunnable timeoutRunnable = new TimeoutRunnable(workerThread, httpRequestRunnable, sd);
            Thread timeoutThread = new Thread(timeoutRunnable);
            timeoutThread.start();
    
            for(int i=0; i<30; i++) {
                System.out.println("workerThread.getState():"+workerThread.getState()+" timeoutThread.getState():"+timeoutThread.getState());
    
                try { // Sleep for 1 second
                    Thread.sleep(1*1000);
                } catch (Exception ex) {
                    ex.printStackTrace();
                }
            }
    
            long endTime = System.currentTimeMillis();
            System.out.println("main End timeInSeconds:"+(endTime-startTime)/1000);
        }
    
        public static class HttpRequestRunnable implements Runnable {
    
            SharedData sharedData;
            public HttpRequestRunnable (SharedData sharedData) {
                this.sharedData = sharedData;
                sharedData.setIsFinished(this, false);
            }
    
            public void run() {
                System.out.println("Running HttpRequestRunnable Runner Start");
                long startTime = System.currentTimeMillis();
                try {
                    HttpGet httpGet = new HttpGet(URL_THAT_CAUSES_CONNECTION_TIMED_OUT_AFTER_20_SECONDS);
                    CloseableHttpResponse response = new DefaultHttpClient().execute(httpGet);
                    String responseString = EntityUtils.toString(response.getEntity());
                    System.out.println("responseString:"+responseString);
    
                    sharedData.setIsFinished(this, true);
                } catch (Exception ex) {
                    ex.printStackTrace();
                }
                long endTime = System.currentTimeMillis();
                System.out.println("Running HttpRequestRunnable Runner End timeInSeconds:"+(endTime-startTime)/1000);
            }
        }
    
        public static class SharedData {
            Map<Runnable, Boolean> isFinishedMap = Collections.synchronizedMap(new LinkedHashMap<Runnable, Boolean>());
            public void setIsFinished(Runnable runnable, Boolean value) {
                synchronized(isFinishedMap) {
                    isFinishedMap.put(runnable, value);
                }
            }
            public Boolean getIsFinished(Runnable runnable) {
                synchronized(isFinishedMap) {
                    return isFinishedMap.get(runnable);
                }
            }
        }
    
        public static class TimeoutRunnable implements Runnable {
            Thread workerThreadToKillIfItTakesTooLong;
            Runnable runnable;
            SharedData sharedData;
            public TimeoutRunnable(Thread workerThreadToKillIfItTakesTooLong, Runnable runnable, SharedData sharedData) {
                this.workerThreadToKillIfItTakesTooLong = workerThreadToKillIfItTakesTooLong;
                this.runnable = runnable;
                this.sharedData = sharedData;
            }
    
            public void run() {
                System.out.println("Running TimeoutRunnable Runnable Start");
                long startTime = System.currentTimeMillis();
                int secondsToSleep = 1;
                int iterationsPerNote = 2;
                int iterations = 10;
                for(int i=0; i<iterations; i++) { // Sleep for at most 10 seconds
                    boolean workerRunnableIsFinished = sharedData.getIsFinished(runnable);
                    if(workerRunnableIsFinished) {
                        return;
                    } else {
                        if(i % iterationsPerNote == 0) { // Print a message every 2 iterations
                            System.out.println("TimeoutRunnable waiting for workerRunnable...");
                        }
                    }
                    try { // Sleep for 1 second
                        Thread.sleep(secondsToSleep*1000);
                    } catch (Exception ex) {
                        ex.printStackTrace();
                    }
                }
    
                // 5 minutes have passed, kill thread
                System.out.println("Killing worker thread for taking too long");
                workerThreadToKillIfItTakesTooLong.stop();
    
                sharedData.setIsFinished(runnable, true);
    
                long endTime = System.currentTimeMillis();
                System.out.println("Running TimeoutRunnable Runnable End timeInSeconds:"+(endTime-startTime)/1000);
            }
    
        }
    }
    

    这是输出

    main: main Start
    main: Starting HTTPS Request Thread
    main: Starting Timeout Thread
    1st_: Running HttpRequestRunnable Runner Start
    main: workerThread.getState():RUNNABLE timeoutThread.getState():RUNNABLE
    2nd_: Running TimeoutRunnable Runnable Start
    2nd_: TimeoutRunnable waiting for workerRunnable...
    main: workerThread.getState():RUNNABLE timeoutThread.getState():RUNNABLE
    2nd_: TimeoutRunnable waiting for workerRunnable...
    main: workerThread.getState():RUNNABLE timeoutThread.getState():RUNNABLE
    main: workerThread.getState():RUNNABLE timeoutThread.getState():RUNNABLE
    2nd_: TimeoutRunnable waiting for workerRunnable...
    main: workerThread.getState():RUNNABLE timeoutThread.getState():RUNNABLE
    main: workerThread.getState():RUNNABLE timeoutThread.getState():TIMED_WAITING
    2nd_: TimeoutRunnable waiting for workerRunnable...
    main: workerThread.getState():RUNNABLE timeoutThread.getState():RUNNABLE
    main: workerThread.getState():RUNNABLE timeoutThread.getState():TIMED_WAITING
    2nd_: TimeoutRunnable waiting for workerRunnable...
    main: workerThread.getState():RUNNABLE timeoutThread.getState():RUNNABLE
    main: workerThread.getState():RUNNABLE timeoutThread.getState():TIMED_WAITING
    2nd_: Killing worker thread for taking too long
    main: workerThread.getState():RUNNABLE timeoutThread.getState():RUNNABLE
    2nd_: Running TimeoutRunnable Runnable End timeInSeconds:10
    main: workerThread.getState():RUNNABLE timeoutThread.getState():TERMINATED
    main: workerThread.getState():RUNNABLE timeoutThread.getState():TERMINATED
    main: workerThread.getState():RUNNABLE timeoutThread.getState():TERMINATED
    main: workerThread.getState():RUNNABLE timeoutThread.getState():TERMINATED
    main: workerThread.getState():RUNNABLE timeoutThread.getState():TERMINATED
    main: workerThread.getState():RUNNABLE timeoutThread.getState():TERMINATED
    main: workerThread.getState():RUNNABLE timeoutThread.getState():TERMINATED
    main: workerThread.getState():RUNNABLE timeoutThread.getState():TERMINATED
    main: workerThread.getState():RUNNABLE timeoutThread.getState():TERMINATED
    main: workerThread.getState():RUNNABLE timeoutThread.getState():TERMINATED
    main: workerThread.getState():RUNNABLE timeoutThread.getState():TERMINATED
    main: workerThread.getState():TERMINATED timeoutThread.getState():TERMINATED
    main: workerThread.getState():TERMINATED timeoutThread.getState():TERMINATED
    main: workerThread.getState():TERMINATED timeoutThread.getState():TERMINATED
    main: workerThread.getState():TERMINATED timeoutThread.getState():TERMINATED
    main: workerThread.getState():TERMINATED timeoutThread.getState():TERMINATED
    main: workerThread.getState():TERMINATED timeoutThread.getState():TERMINATED
    main: workerThread.getState():TERMINATED timeoutThread.getState():TERMINATED
    main: workerThread.getState():TERMINATED timeoutThread.getState():TERMINATED
    main: main End timeInSeconds:30
    

    我使用 SharedData 类来保存两个线程所需的信息。通过添加终止线程所需的额外信息(即 HttpGet),我可以让监控线程执行实际终止线程所需的任何操作(即调用 httpGet.abort)。这是修改后的代码(修改后的行以 // MOD 结尾)

    import java.util.Collections;
    import java.util.LinkedHashMap;
    import java.util.Map;
    import org.apache.http.client.methods.CloseableHttpResponse;
    import org.apache.http.client.methods.HttpGet;
    import org.apache.http.impl.client.DefaultHttpClient;
    import org.apache.http.util.EntityUtils;
    
    public class A_Test_Thread_Interrupt {
        public static final String      public static final String URL_THAT_CAUSES_CONNECTION_TIMED_OUT_AFTER_20_SECONDS = "https://..."; // Need to provide this for your system.  Must timeout after 20 seconds
    //  java.net.ConnectException: Connection timed out: connect
    //  at java.net.DualStackPlainSocketImpl.connect0(Native Method)
    //  at java.net.DualStackPlainSocketImpl.socketConnect(DualStackPlainSocketImpl.java:79)
    //  at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:350)
    //  at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:206)
    //  at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:188)
    //  at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:172)
    //  at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
    //  at java.net.Socket.connect(Socket.java:589)
    //  at org.apache.http.conn.ssl.SSLSocketFactory.connectSocket(SSLSocketFactory.java:542)
    //  at org.apache.http.conn.ssl.SSLSocketFactory.connectSocket(SSLSocketFactory.java:414)
    //  at org.apache.http.impl.conn.DefaultClientConnectionOperator.openConnection(DefaultClientConnectionOperator.java:180)
    //  at org.apache.http.impl.conn.ManagedClientConnectionImpl.open(ManagedClientConnectionImpl.java:326)
    //  at org.apache.http.impl.client.DefaultRequestDirector.tryConnect(DefaultRequestDirector.java:610)
    //  at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:445)
    //  at org.apache.http.impl.client.AbstractHttpClient.doExecute(AbstractHttpClient.java:835)
    //  at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:83)
    //  at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:108)
    //  at A_Test_Thread_Interrupt$HttpRequestRunnable.run(A_Test_Thread_Interrupt.java:35)
    //  at java.lang.Thread.run(Thread.java:748)
    
        public static void main(String[] args) {
            System.out.println("main Start");
            long startTime = System.currentTimeMillis();
    
            SharedData sd = new SharedData();
    
            System.out.println("Starting HTTPS Request Thread");
            HttpRequestRunnable httpRequestRunnable = new HttpRequestRunnable(sd);
            Thread workerThread = new Thread(httpRequestRunnable);
            workerThread.start();
    
    //      workerThread.stop();
    
            System.out.println("Starting Timeout Thread");
            TimeoutRunnable timeoutRunnable = new TimeoutRunnable(workerThread, httpRequestRunnable, sd);
            Thread timeoutThread = new Thread(timeoutRunnable);
            timeoutThread.start();
    
            for(int i=0; i<30; i++) {
                System.out.println("workerThread.getState():"+workerThread.getState()+" timeoutThread.getState():"+timeoutThread.getState());
    
                try { // Sleep for 1 second
                    Thread.sleep(1*1000);
                } catch (Exception ex) {
                    ex.printStackTrace();
                }
            }
    
            long endTime = System.currentTimeMillis();
            System.out.println("main End timeInSeconds:"+(endTime-startTime)/1000);
        }
    
        public static class HttpRequestRunnable implements Runnable {
    
            SharedData sharedData;
            public HttpRequestRunnable (SharedData sharedData) {
                this.sharedData = sharedData;
                sharedData.setIsFinished(this, false);
            }
    
            public void run() {
                System.out.println("Running HttpRequestRunnable Runner Start");
                long startTime = System.currentTimeMillis();
                try {
                    HttpGet httpGet = new HttpGet(URL_THAT_CAUSES_CONNECTION_TIMED_OUT_AFTER_20_SECONDS);
                    sharedData.setHttpGet(this, httpGet); // MOD
    
                    CloseableHttpResponse response = new DefaultHttpClient().execute(httpGet);
                    String responseString = EntityUtils.toString(response.getEntity());
                    System.out.println("responseString:"+responseString);
    
                    sharedData.setIsFinished(this, true);
                } catch (Exception ex) {
                    ex.printStackTrace();
                }
                long endTime = System.currentTimeMillis();
                System.out.println("Running HttpRequestRunnable Runner End timeInSeconds:"+(endTime-startTime)/1000);
            }
        }
    
        public static class SharedData {
            Map<Runnable, Boolean> isFinishedMap = Collections.synchronizedMap(new LinkedHashMap<Runnable, Boolean>());
            Map<Runnable, HttpGet> httpGetMap = Collections.synchronizedMap(new LinkedHashMap<Runnable, HttpGet>()); // MOD
            public void setIsFinished(Runnable runnable, Boolean value) {
                synchronized(isFinishedMap) {
                    isFinishedMap.put(runnable, value);
                }
            }
            public Boolean getIsFinished(Runnable runnable) {
                synchronized(isFinishedMap) {
                    return isFinishedMap.get(runnable);
                }
            }
            public void setHttpGet(Runnable runnable, HttpGet httpGet) { // MOD
                synchronized(httpGetMap) { // MOD
                    httpGetMap.put(runnable, httpGet); // MOD
                } // MOD
            } // MOD
            public HttpGet getHttpGet(Runnable runnable) { // MOD
                synchronized(httpGetMap) { // MOD
                    return httpGetMap.get(runnable); // MOD
                } // MOD
            } // MOD
        }
    
        public static class TimeoutRunnable implements Runnable {
            Thread workerThreadToKillIfItTakesTooLong;
            Runnable runnable;
            SharedData sharedData;
            public TimeoutRunnable(Thread workerThreadToKillIfItTakesTooLong, Runnable runnable, SharedData sharedData) {
                this.workerThreadToKillIfItTakesTooLong = workerThreadToKillIfItTakesTooLong;
                this.runnable = runnable;
                this.sharedData = sharedData;
            }
    
            public void run() {
                System.out.println("Running TimeoutRunnable Runnable Start");
                long startTime = System.currentTimeMillis();
                int secondsToSleep = 1;
                int iterationsPerNote = 2;
                int iterations = 10;
                for(int i=0; i<iterations; i++) { // Sleep for at most 10 seconds
                    boolean workerRunnableIsFinished = sharedData.getIsFinished(runnable);
                    if(workerRunnableIsFinished) {
                        return;
                    } else {
                        if(i % iterationsPerNote == 0) { // Print a message every 2 iterations
                            System.out.println("TimeoutRunnable waiting for workerRunnable...");
                        }
                    }
                    try { // Sleep for 1 second
                        Thread.sleep(secondsToSleep*1000);
                    } catch (Exception ex) {
                        ex.printStackTrace();
                    }
                }
    
                // 5 minutes have passed, kill thread
                System.out.println("Killing worker thread for taking too long");
                workerThreadToKillIfItTakesTooLong.stop();
    
                HttpGet httpGet = sharedData.getHttpGet(runnable); // MOD
                httpGet.abort(); // MOD
    
                sharedData.setIsFinished(runnable, true);
    
                long endTime = System.currentTimeMillis();
                System.out.println("Running TimeoutRunnable Runnable End timeInSeconds:"+(endTime-startTime)/1000);
            }
    
        }
    }
    

    这是修改后的输出

    main: main Start
    main: Starting HTTPS Request Thread
    main: Starting Timeout Thread
    1st_: Running HttpRequestRunnable Runner Start
    main: workerThread.getState():RUNNABLE timeoutThread.getState():RUNNABLE
    2nd_: Running TimeoutRunnable Runnable Start
    2nd_: TimeoutRunnable waiting for workerRunnable...
    main: workerThread.getState():RUNNABLE timeoutThread.getState():RUNNABLE
    2nd_: TimeoutRunnable waiting for workerRunnable...
    main: workerThread.getState():RUNNABLE timeoutThread.getState():RUNNABLE
    main: workerThread.getState():RUNNABLE timeoutThread.getState():TIMED_WAITING
    main: workerThread.getState():RUNNABLE timeoutThread.getState():RUNNABLE
    2nd_: TimeoutRunnable waiting for workerRunnable...
    main: workerThread.getState():RUNNABLE timeoutThread.getState():RUNNABLE
    main: workerThread.getState():RUNNABLE timeoutThread.getState():RUNNABLE
    2nd_: TimeoutRunnable waiting for workerRunnable...
    main: workerThread.getState():RUNNABLE timeoutThread.getState():RUNNABLE
    2nd_: TimeoutRunnable waiting for workerRunnable...
    main: workerThread.getState():RUNNABLE timeoutThread.getState():RUNNABLE
    main: workerThread.getState():RUNNABLE timeoutThread.getState():RUNNABLE
    2nd_: Killing worker thread for taking too long
    main: workerThread.getState():RUNNABLE timeoutThread.getState():RUNNABLE
    2nd_: Running TimeoutRunnable Runnable End timeInSeconds:10
    main: workerThread.getState():TERMINATED timeoutThread.getState():TERMINATED
    main: workerThread.getState():TERMINATED timeoutThread.getState():TERMINATED
    main: workerThread.getState():TERMINATED timeoutThread.getState():TERMINATED
    main: workerThread.getState():TERMINATED timeoutThread.getState():TERMINATED
    main: workerThread.getState():TERMINATED timeoutThread.getState():TERMINATED
    main: workerThread.getState():TERMINATED timeoutThread.getState():TERMINATED
    main: workerThread.getState():TERMINATED timeoutThread.getState():TERMINATED
    main: workerThread.getState():TERMINATED timeoutThread.getState():TERMINATED
    main: workerThread.getState():TERMINATED timeoutThread.getState():TERMINATED
    main: workerThread.getState():TERMINATED timeoutThread.getState():TERMINATED
    main: workerThread.getState():TERMINATED timeoutThread.getState():TERMINATED
    main: workerThread.getState():TERMINATED timeoutThread.getState():TERMINATED
    main: workerThread.getState():TERMINATED timeoutThread.getState():TERMINATED
    main: workerThread.getState():TERMINATED timeoutThread.getState():TERMINATED
    main: workerThread.getState():TERMINATED timeoutThread.getState():TERMINATED
    main: workerThread.getState():TERMINATED timeoutThread.getState():TERMINATED
    main: workerThread.getState():TERMINATED timeoutThread.getState():TERMINATED
    main: workerThread.getState():TERMINATED timeoutThread.getState():TERMINATED
    main: workerThread.getState():TERMINATED timeoutThread.getState():TERMINATED
    main: main End timeInSeconds:30
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-08-29
      • 1970-01-01
      • 2016-03-26
      • 2017-03-10
      相关资源
      最近更新 更多