各位高手,帮小弟看看这个applet的线程为什么不能启动?
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){}
}
}
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){}
}
}
...全文
相关推荐
中国房地产市场报告(2021年第一季度)2021.4(15页).pdf
中国房地产市场报告(2021年第一季度)2021.4(15页).pdf
2021年第一季度中国电影市场报告.pdf
2021年第一季度中国电影市场报告.pdf
2021第一季度中国电影市场报告—行业报告.pdf
2021第一季度中国电影市场报告—行业报告.pdf
2021年第一季度中国家庭的财富变动趋势-中国家庭金融-蚂蚁-2021-35页(1).pdf
2021年第一季度中国家庭的财富变动趋势-中国家庭金融-蚂蚁-2021-35页(1).pdf
2021年第一季度中国电影市场报告.rar
2021年第一季度中国电影市场报告.rar


Java SE
