各位高手,帮小弟看看这个applet的线程为什么不能启动?

wxfJordan wxfJordan 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
import java.io.FileWriter;
import java.io.BufferedWriter;
import java.net.URL;
import java.text.SimpleDateFormat;
import java.util.Date;
import org.apache.axis.client.Call;
import org.apache.axis.client.Service;

import java.applet.Applet;
import java.awt.*;


public class DataApplet extends Applet implements Runnable
{
private FileWriter outputFile;
private BufferedWriter output;

private String endpoint,res,printTime;
private Service service;
private Call call;

public void init()
{

try{
outputFile=new FileWriter("text.txt");
output=new BufferedWriter(outputFile);

endpoint="http://localhost:8080/axis/TestConnectMySql.jws";
service=new Service();
call=(Call)service.createCall();
call.setTargetEndpointAddress(new URL(endpoint));
call.setOperationName("connectMySql");
res=null;
printTime=new SimpleDateFormat("HH:mm:ss").format(new Date());
new Thread(this).start();

}
catch(Exception e){}
}
public void run()
{

try
{
while(true)
{
//data of mysql
res=(String)call.invoke(new Object[]{printTime});
System.out.println(printTime+" ");
printTime=new SimpleDateFormat("HH:mm:ss").format(new Date());
//data will output if res is not null
if (res!=null && !res.equals(""))
{
output.write(res,0,res.length());
output.newLine();
output.flush();
System.out.println(res+"\n");
}
//per 5 second printout
Thread.sleep(5000);
}//the end of while
}
catch(Exception ex){}
}
}
...全文
评论 1
收藏 已收藏
分享
返回顶部
wxfJordan
Java SE 62,621 成员 307,251 内容