📄 workthread.java
字号:
/* * 10/01/2001 - 15:52:00 * * FtpGUI - Ftp client written in Java * Copyright (C) 2001 Kostadin Kirilov Kostadinov * k3co@hotmail.com * sourceforge.net * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */package ftpgui;/** * Title: FtpGUI * Description: * Copyright: Copyright (c) 2001 * Company: * @author * @version 1.0 */import java.util.*;import java.lang.reflect.*;public class Workthread extends Thread{ Vector m_vTasks=new Vector(); Hashtable m_htTasks=new Hashtable(); Hashtable m_htTaskResults=new Hashtable(); Hashtable m_htTaskExceptions=new Hashtable(); private boolean m_booRuning=false; public Workthread() { } private static long m_lCounter=0; public static String genUniqueID() { return (String.valueOf(System.currentTimeMillis())+String.valueOf(m_lCounter++)); } public String addInInvocationQueue(Method objMethod,Object obj, Object[] args) { Task objTask=new Task(objMethod ,obj,args ); return addTask(objTask); } public String addTask(Task objTask) { String strID=genUniqueID(); m_htTasks.put(strID,objTask); m_vTasks.addElement(strID); startWorking(); return strID; } public void startWorking() { if(!m_booRuning) { m_booRuning=true; System.out.println("this.start();"); this.start(); } } public void stopWorking(boolean boo) { m_booRuning=boo; } public void run() { String strID=null; try { while(m_booRuning) { if(m_vTasks.isEmpty()) { //System.out.println("Sleeping"); sleep(200); continue; //m_booRuning=false; //System.out.println("m_booRuning=false; Finished"); //return; } strID=(String)m_vTasks.firstElement(); Task objTask=(Task)m_htTasks.get(strID); System.out.println("Executing task strID="+strID); Object objResult=objTask.execTask(); if(objResult!=null) m_htTaskResults.put(strID,objResult); m_vTasks.remove(strID); strID=null; } }catch(Exception e) { if(strID!=null) { m_htTaskExceptions.put(strID,e); m_vTasks.remove(strID); e.printStackTrace(); } } } public Exception getException(String strID) { Object obj=m_htTaskExceptions.get(strID); if(obj!=null) { m_htTaskExceptions.remove(strID); } return (Exception)obj; } public Object getResult(String strID) { Object obj=m_htTaskResults.get(strID); if(obj!=null) { m_htTaskResults.remove(strID); } return obj; }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -