怎么样让java的主线程等待? Thread.join()(如果其他线程只是发送消息,没有其他任务)或者使用一个信号量主线程s.wait();其他线程socket消息发完后s.notify(); 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 // Create and start a thread Thread thread = new MyThread(); thread.start(); // Check if the thread has finished in a non-blocking way if (thread.isAlive()) { // Thread has not finished } else { // Finished } // Wait for the thread to finish but don't wait longer than a // specified time long delayMillis = 5000; // 5 seconds try { thread.join(delayMillis); if (thread.isAlive()) { // Timeout occurred; thread has not finished } else { // Finished } } catch (InterruptedException e) { // Thread was interrupted } // Wait indefinitely for the thread to finish try { thread.join(); // Finished } catch (InterruptedException e) { // Thread was interrupted } 在主线程里用Thread.sleep()不行吗? java异常 已知XML里面保存图片的原始数据,求还原图片的方法~ 有关二维数组分组排序的问题 检测这个包中类的个数时,却返回了一个空值 请各位推荐下学习javabean的书籍或者文章?? 在java中,怎样使用另外一个类中的对象…………在线等 请教一个jar打包后运行错误的问题 怎样可以使JAVA入门快点??? 简单问题,送分啦! 小问题:JAVA中弹出一个提示信息窗口是什么? jdbc连Sqlserver2000的问题 用applet可以实现从服务器上下载文件到客户端,而不出现保存对话框么
Thread thread = new MyThread();
thread.start();
// Check if the thread has finished in a non-blocking way
if (thread.isAlive()) {
// Thread has not finished
} else {
// Finished
}
// Wait for the thread to finish but don't wait longer than a
// specified time
long delayMillis = 5000; // 5 seconds
try {
thread.join(delayMillis);
if (thread.isAlive()) {
// Timeout occurred; thread has not finished
} else {
// Finished
}
} catch (InterruptedException e) {
// Thread was interrupted
}
// Wait indefinitely for the thread to finish
try {
thread.join();
// Finished
} catch (InterruptedException e) {
// Thread was interrupted
}