当前位置: 技术问答>java相关
我的代码 为什么 只执行了 一半????(急)
来源: 互联网 发布时间:2015-07-01
本文导语: //TimerRobot.java package org.netbee.news.robot; public class TimerRobot extends Thread{ //private long interval = 60000*60*12; //12Сʱ private long interval = 60000*3; //12Сʱ public TimerRobot(){} public TimerRobot(long inter...
//TimerRobot.java
package org.netbee.news.robot;
public class TimerRobot extends Thread{
//private long interval = 60000*60*12; //12Сʱ
private long interval = 60000*3; //12Сʱ
public TimerRobot(){}
public TimerRobot(long interval){
this.interval = interval;
}
public void run() {
try{
while(true){
sleep(interval);
work();
}
} catch (Exception e){}
}
public void work(){}
}
-----------------------------------------------
//NewsRobot.java
package org.netbee.news.robot;
import org.netbee.util.*;
import java.util.*;
public class NewsRobot extends TimerRobot{
private static Object initLock = new Object();
private static NewsRobot newsRobot = null;
public static NewsRobot getInstance() {
if (newsRobot == null) {
synchronized(initLock) {
if (newsRobot == null) {
try {
Class c = Class.forName("org.netbee.news.robot.NewsRobot");
newsRobot = (NewsRobot)c.newInstance();
}
catch (Exception e) {
System.err.println("×°ÔØ NewsCatalogFactory Ààʧ°Ü News cannot function normally.");
e.printStackTrace();
return null;
}
}
}
}
return newsRobot;
}
public void orderWork(){
try{
this.start();
} catch (IllegalThreadStateException itse){
this.resume();
}
}
public void killRobot(){
this.suspend();
}
public void work(){
System.out.println("-----------------");
//String data = FileUtils.getRemotePage("http://news.sina.com.cn/news1000.shtml");
String data = FileUtils.getRemotePage("http://192.168.0.100:8080/news/newstest.jsp");
int beginIndex = data.indexOf("");
int endIndex = data.indexOf("");
data = data.substring( beginIndex, endIndex );
System.out.println("data==="+data);
//&&&^^&*$*$*^$*&$*& 为什么只 打印出 data 就没反应了 &%***
StringTokenizer newstk = new StringTokenizer( data, "");
String oneNesw, catalog , url ,news;
while(newstk.hasMoreTokens()){
oneNesw = (String)newstk.nextElement();
beginIndex = oneNesw.indexOf("[");
endIndex = oneNesw.indexOf("]");
catalog = oneNesw.substring( beginIndex, endIndex );
System.out.println("catalog==="+catalog);
if(catalog == "国内" || catalog == "国际") {
beginIndex = oneNesw.indexOf("");
url = oneNesw.substring( beginIndex, endIndex );
//news = FileUtils.getRemotePage( url );
System.out.println("news==="+url);
}
}
}
}
=================================================
jsp 调用页面
=================
jsp 中止页面
请高手指点
package org.netbee.news.robot;
public class TimerRobot extends Thread{
//private long interval = 60000*60*12; //12Сʱ
private long interval = 60000*3; //12Сʱ
public TimerRobot(){}
public TimerRobot(long interval){
this.interval = interval;
}
public void run() {
try{
while(true){
sleep(interval);
work();
}
} catch (Exception e){}
}
public void work(){}
}
-----------------------------------------------
//NewsRobot.java
package org.netbee.news.robot;
import org.netbee.util.*;
import java.util.*;
public class NewsRobot extends TimerRobot{
private static Object initLock = new Object();
private static NewsRobot newsRobot = null;
public static NewsRobot getInstance() {
if (newsRobot == null) {
synchronized(initLock) {
if (newsRobot == null) {
try {
Class c = Class.forName("org.netbee.news.robot.NewsRobot");
newsRobot = (NewsRobot)c.newInstance();
}
catch (Exception e) {
System.err.println("×°ÔØ NewsCatalogFactory Ààʧ°Ü News cannot function normally.");
e.printStackTrace();
return null;
}
}
}
}
return newsRobot;
}
public void orderWork(){
try{
this.start();
} catch (IllegalThreadStateException itse){
this.resume();
}
}
public void killRobot(){
this.suspend();
}
public void work(){
System.out.println("-----------------");
//String data = FileUtils.getRemotePage("http://news.sina.com.cn/news1000.shtml");
String data = FileUtils.getRemotePage("http://192.168.0.100:8080/news/newstest.jsp");
int beginIndex = data.indexOf("");
int endIndex = data.indexOf("");
data = data.substring( beginIndex, endIndex );
System.out.println("data==="+data);
//&&&^^&*$*$*^$*&$*& 为什么只 打印出 data 就没反应了 &%***
StringTokenizer newstk = new StringTokenizer( data, "
String oneNesw, catalog , url ,news;
while(newstk.hasMoreTokens()){
oneNesw = (String)newstk.nextElement();
beginIndex = oneNesw.indexOf("[");
endIndex = oneNesw.indexOf("]");
catalog = oneNesw.substring( beginIndex, endIndex );
System.out.println("catalog==="+catalog);
if(catalog == "国内" || catalog == "国际") {
beginIndex = oneNesw.indexOf("");
url = oneNesw.substring( beginIndex, endIndex );
//news = FileUtils.getRemotePage( url );
System.out.println("news==="+url);
}
}
}
}
=================================================
jsp 调用页面
=================
jsp 中止页面
请高手指点
|
确定数据都读到了?使用的分隔标志都有?只凭看,要看出程序的问题,至少对我来讲,有些困难.
|
线程时间问题!