public synchronized void WritePort(final String Msg)
{
final Object lock = new Object();
boolean writeSucess = false; class wt implements Runnable{
public void run(){
try
{
System.out.println("start write port");
for (int i = 0; i < Msg.length(); i++){
os.write(Msg.charAt(i));
}
os.flush();
} catch (IOException e) {
System.out.println("WritePort exception");
}
System.out.println(" write port over");
lock.notifyAll();
}
} try {
while (!writeSucess) {
new Thread(new wt()).start();
lock.wait(300);
writeSucess = true;
}
}catch (InterruptedException ex) {
System.out.println("Printer timeout!");
}
}如何等里面的内部线程超时退出啊,
{
final Object lock = new Object();
boolean writeSucess = false; class wt implements Runnable{
public void run(){
try
{
System.out.println("start write port");
for (int i = 0; i < Msg.length(); i++){
os.write(Msg.charAt(i));
}
os.flush();
} catch (IOException e) {
System.out.println("WritePort exception");
}
System.out.println(" write port over");
lock.notifyAll();
}
} try {
while (!writeSucess) {
new Thread(new wt()).start();
lock.wait(300);
writeSucess = true;
}
}catch (InterruptedException ex) {
System.out.println("Printer timeout!");
}
}如何等里面的内部线程超时退出啊,
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货