首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > JAVA > J2EE开发 >

java线程同步有关问题来看看

2012-03-19 
java线程同步问题高手进来看看package com.admomo.scrape.utilimport java.io.Fileimport java.sql.Prep

java线程同步问题高手进来看看
package com.admomo.scrape.util;

import java.io.File;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.HashMap;
import java.util.Map;

import com.acwoan.core.orm.DAOUtil;
import com.acwoan.core.util.StdLib;

public class GuanliWeibo extends Thread {

long next;
Thread thread = new Thread();

//main方法入口
public static void main(String[] args){
int i = 3000;
Thread thread = new Thread();
GuanliWeibo guanli = new GuanliWeibo();
guanli.run();
try {
while(true){
thread.sleep(i);
System.out.println("main入口 循环调用notifyWait方面!");
guanli.notifyWait();
}
} catch (Exception e) {
// TODO: handle exception
}
}

public void run(){
try {
while (true) {

next = 30;
//同步锁
synchronized(this){
System.out.println("线程进入等待阶段!");
//进入等待阶段,以毫秒计算,等待时间差
thread.wait(next);
// function
uploadSinaWeibo();
}
}
}catch (Exception e) {
// TODO: handle exception
}
}

//启动run方面中的等待线程
public void notifyWait(){
synchronized(this){
thread.notify();
System.out.println("启动run方面中的等待线程");
}
}
}

[解决办法]
唯一想说的就是启用线程你应该调用start()方法。其他没什么好说的,也不懂你想问什么。
[解决办法]
你看看线程知识的介绍呢,启动线程是要调用start()方法的,线程启动后会自动调用run方法
[解决办法]
启用线程你应该调用start()方法

热点排行