How interrupt/stop a thread in Java?

后端 未结 8 1793
失恋的感觉
失恋的感觉 2020-12-05 07:48

I\'m trying to stop a thread but I can\'t do that :

public class Middleware {

public void read() {
    try {
        socket = new Socket(\"192.168.1.8\", 20         


        
8条回答
  •  我在风中等你
    2020-12-05 08:47

    if you want to interrupt a running thread, then you need to have access to the thread object.

    thread = new Thread(scan);
    thread.start();
    

    then say

    thread.interrupt();
    

    this will interrupt the running thread.

提交回复
热议问题