62,623
社区成员
发帖
与我相关
我的任务
分享
public class TestThread
{
public static void main(String[] args) {
String aaa = "原来的数据";
try {
MyThread aa = new MyThread();
aa.start();
//设置最长等待两秒
aa.join(2 * 1000);
aaa = aa.getAAA()!=null?aa.getAAA():aaa;
} catch (Exception e) {
// TODO: handle exception
}
System.out.println("aaa=" + aaa);
}
}
class MyThread extends Thread {
private String rs=null;
public String getAAA()
{
return rs;
}
private String _getAAA() {
//你的真正代码放在此处
long start = System.currentTimeMillis();
long end = 0;
while (true) {
end = System.currentTimeMillis();
// System.out.println((end - start)/1000);
if ((end - start) / 1000 >= 10) {// 已经过10秒
return "getaaa";
}
}
}
public void run()
{
rs=_getAAA();
}
}
/**
* @author XuHuiJun
*
*/
public class Test {
/**
* @param args
*/
public static void main(String[] args) {
String aaa = "原来的数据";
try {
MyThread aa = new MyThread();
aa.start();
//设置最长等待两秒
aa.join(2 * 1000);
aaa = aa.getAAA();
} catch (Exception e) {
// TODO: handle exception
}
System.out.println("aaa=" + aaa);
}
}
class MyThread extends Thread {
public String getAAA() {
long start = System.currentTimeMillis();
long end = 0;
while (true) {
end = System.currentTimeMillis();
System.out.println((end - start)/1000);
if ((end - start) / 1000 >= 10) {// 已经过10秒
return "getaaa";
}
}
}
}
package zhao;
public class Test11{
public static void main(String[] args) {
String aaa= "原来的数据";
aaa=getAAA();
System.out.println("aaa="+aaa);
}
private static String getAAA(){
long start = System.currentTimeMillis();
long end = 0;
while(true) {
System.out.print("hi");
end = System.currentTimeMillis();
if((end-start)/1000>=10) {//已经过10秒
return "getaaa";
}
}
//return "getaaa";
}
}