我使用swing做小应用程序,需要在运行时开启一个线程做监听器,我是这样写的:
public synchronized void listen() {
try {
_transport.listen();
} catch (IOException ioex) {
System.out.println("Unable to listen: " + ioex);
System.exit(-1);
} System.out.println("Waiting for traps..");
try {
this.wait();// Wait for traps to come in
} catch (InterruptedException ex) {
System.out.println("Interrupted while waiting for traps: " + ex);
System.exit(-1);
}
}结果程序一运行到这里就不往下走了,整个死掉,请问我该怎样做才能不影响我的程序运行呢?
public synchronized void listen() {
try {
_transport.listen();
} catch (IOException ioex) {
System.out.println("Unable to listen: " + ioex);
System.exit(-1);
} System.out.println("Waiting for traps..");
try {
this.wait();// Wait for traps to come in
} catch (InterruptedException ex) {
System.out.println("Interrupted while waiting for traps: " + ex);
System.exit(-1);
}
}结果程序一运行到这里就不往下走了,整个死掉,请问我该怎样做才能不影响我的程序运行呢?
解决方案 »
- 怎样快速上手JAVA
- 每日一题1
- static变量
- 关于JAVA连接SQLServer2000的问题,为什么总是java.sql.SQLException: [Microsoft][SQLServer 2000 Driver for JDBC]Error establishing
- 根据日期(20050907)获得这是星期几?
- 一个一直疑惑不解的问题
- 100分求
- 一个ResultSet 在执行一次查询操作后,没有关闭,是否可以再执行另一次查询操作?
- 用一直线连接鼠标在panel的两点,,有2点疑问,,
- 看来大家都喜欢讨论已有答案的问题,对疑难杂症不屑一顾,唉,真衰啊。
- XP系统下JDBC连接SQL2000的问题
- 我该如何用java执行dos下应用程序
然后启动一个线程实例看你的代码 就是一个单线程的
来唤醒等待的线程,不过你这种写法没看出来有什么用?
public void run() {
try {
File music = new File(iSystemConstants.muiscfile);
Player player = new Player(new FileInputStream(music));
player.play();
} catch (FileNotFoundException ex) {
} catch (JavaLayerException ex) {
} }
});
//thread.start();