相关疑难解决方法(0)

我怎么能杀死一个线程?不使用stop();

Thread currentThread=Thread.currentThread();
        public void run()
        {               

             while(!shutdown)
            {                               
                try
                {
                    System.out.println(currentThread.isAlive());
                Thread.interrupted();

                System.out.println(currentThread.isAlive());
                if(currentThread.isAlive()==false)
                {
                    shutdown=true;
                }
                }
                catch(Exception e)
                {
                    currentThread.interrupt();
                }                   
            }
        }

    });
    thread.start();
Run Code Online (Sandbox Code Playgroud)

java multithreading interrupted-exception interruption

24
推荐指数
3
解决办法
8万
查看次数

Java,如何阻止线程

所以我创建了一个线程

Thread personThread = new Thread(Person);
personThread.start();

/** Now to stop it **/
personThread.stop();
Run Code Online (Sandbox Code Playgroud)

问题是,当我尝试编译时,我得到:warning: [deprecation] stop() in Thread has been deprecated.据我所知,这已经不再使用了.那我怎么能完全停止一个线程,与它的状态无关呢?

java multithreading

4
推荐指数
1
解决办法
1万
查看次数