日期:2014-05-20  浏览次数:20789 次

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()方法