线程的中断
Posted dulute
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了线程的中断相关的知识,希望对你有一定的参考价值。
public class JoinTest extends JFrame { private Thread threadA; final JProgressBar progressBar = new JProgressBar(); public JoinTest() { // TODO Auto-generated constructor stub getContentPane().add(progressBar, BorderLayout.NORTH); progressBar.setStringPainted(true); threadA = new Thread(new Runnable() { int count = 0; public void run() { while (true) { progressBar.setValue(++count); try { Thread.sleep(100); } catch (InterruptedException e) { // TODO: handle exception System.out.println("当前线程序被中断"); break; } } } }); threadA.start(); threadA.interrupt(); } public static void init(JFrame frame,int width,int height) { frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setSize(width, height); frame.setVisible(true); } public static void main(String[] args) { // TODO Auto-generated method stub init(new JoinTest(), 100, 100); } }
以上是关于线程的中断的主要内容,如果未能解决你的问题,请参考以下文章
newCacheThreadPool()newFixedThreadPool()newScheduledThreadPool()newSingleThreadExecutor()自定义线程池(代码片段