interrupt 的用法??
对这个程序的输出的问题
package thinkInJava;
import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import javax.swing.JApplet;
import javax.swing.JButton;
import javax.swing.JFrame;
class Blocked extends Thread {
public synchronized void run() {
System.out.println("before wait ");
try {
wait(); // Blocks
} catch (InterruptedException e) {
System.out.println("InterruptedException");
}
System.out.println("Exiting run()");
}
}
public class Interrupt extends JApplet {
private JButton interrupt = new JButton("Interrupt");
private Blocked blocked = new Blocked();
public void init() {
add(interrupt);
interrupt.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
System.out.println("Button pressed");
if (blocked == null)
return;
Thread remove = blocked;
blocked = null; // to release it
System.out.println("aaaaaa");
remove.interrupt();
System.out.println("bbbbbbb");
}
});
blocked.start();
}
public static void main(String[] args) {
Interrupt applet = new Interrupt();
JFrame aFrame = new JFrame("Interrupt");
aFrame.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
System.exit(0);
}
});
aFrame.add(applet, BorderLayout.CENTER);
aFrame.setSize(200, 100);
applet.init();
applet.start();
aFrame.setVisible(true);
}
} // /:~
为何是结果是:
before wait
Button pressed
aaaaaa
bbbbbbb
InterruptedException
Exiting run()
Button pressed
而 不是
before wait
Button pressed
aaaaaa
InterruptedException
Exiting run()
bbbbbbb
Button pressed
package thinkInJava;
import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import javax.swing.JApplet;
import javax.swing.JButton;
import javax.swing.JFrame;
class Blocked extends Thread {
public synchronized void run() {
System.out.println("before wait ");
try {
wait(); // Blocks
} catch (InterruptedException e) {
System.out.println("InterruptedException");
}
System.out.println("Exiting run()");
}
}
public class Interrupt extends JApplet {
private JButton interrupt = new JButton("Interrupt");
private Blocked blocked = new Blocked();
public void init() {
add(interrupt);
interrupt.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
System.out.println("Button pressed");
if (blocked == null)
return;
Thread remove = blocked;
blocked = null; // to release it
System.out.println("aaaaaa");
remove.interrupt();
System.out.println("bbbbbbb");
}
});
blocked.start();
}
public static void main(String[] args) {
Interrupt applet = new Interrupt();
JFrame aFrame = new JFrame("Interrupt");
aFrame.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
System.exit(0);
}
});
aFrame.add(applet, BorderLayout.CENTER);
aFrame.setSize(200, 100);
applet.init();
applet.start();
aFrame.setVisible(true);
}
} // /:~
为何是结果是:
before wait
Button pressed
aaaaaa
bbbbbbb
InterruptedException
Exiting run()
Button pressed
而 不是
before wait
Button pressed
aaaaaa
InterruptedException
Exiting run()
bbbbbbb
Button pressed
...全文
相关推荐
邮件发送、企业微信发送测试程序
邮件发送、企业微信发送测试程序
调用企业微信发送普通邮箱案例带附件
调用企业微信发送普通邮箱案例带附件
Python邮件与企业微信机器人[项目代码]
本文详细介绍了如何使用Python发送邮件以及调用企业微信机器人发送消息。邮件发送部分涵盖了SMTP服务器的配置、邮件内容的构造(包括文本、HTML和图片附件)、以及邮件的发送过程。企业微信机器人部分则讲解了如何通过API上传文件并发送消息到企业微信。文章提供了完整的代码示例,适合需要实现自动化通知功能的开发者参考。
基于jenkins构建结果企业微信提醒
主要介绍了基于jenkins构建结果企业微信提醒,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友可以参考下
企微社交矩阵营销策略方案.pdf
企微社交矩阵营销策略方案.pdf


Java SE
