communicationthreadpool.java
来自「主要是对串口驱动的的一些控制源码!!! 在下载javacomm20-win32」· Java 代码 · 共 123 行
JAVA
123 行
/*
* <br><br><center><table border="1" width="80%"><hr>
* <strong><a href="http://jkf.sourceforge.net">The JKF Project</a></strong>
* <p>
* Copyright (C) 2002 by Marten Wulff
* <p>
* This library 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.1 of the License, or (at your option) any later version.
* <p>
* This library 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.
* <p>
* You should have received a copy of the <a href="http://www.gnu.org/copyleft/lesser.html">
* GNU Lesser General Public License</a> along with this library; if not, write to
* the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston,
* MA 02111-1307 USA
* <hr></table></center>
*
* $Log: CommunicationThreadPool.java,v $
* Revision 1.4 2003/03/12 14:46:53 willaxt
* taskReady() doesn't call task.handleException() any more
* it is now called only when during communication something went wrong
* gui problems are now loggeg via the JKFClientLogger
*
* Revision 1.3 2003/01/16 15:57:50 mwulff
* method taskReady() calls task.handleExcepiton(Exception) if an error occures
*
* Revision 1.2 2003/01/16 15:48:48 mwulff
* method taskReady unlocks gui
*
* Revision 1.1 2003/01/16 13:10:54 mwulff
* initial version
*
* Revision 1.2 2003/01/05 16:31:18 willaxt
* cleaned up imports
* added javadoc comments
*
* Revision 1.1 2002/12/31 12:18:41 mwulff
* no message
*
*/
package de.fhm.jkf.gui;
import de.fhm.jkf.resource.cl.JKFClientLogger;
import de.fhm.jkf.thread.cl.ServerThread;
import de.fhm.jkf.thread.cl.TaskReadyListener;
import de.fhm.jkf.thread.cl.ThreadPool;
/**
* Special <code>ThreadPool</code> implementation for the gui framework.
*
* @author marten wulff
* @version 1.0
*/
public class CommunicationThreadPool
extends ThreadPool
implements TaskReadyListener {
/**
* Hold's the single instace of this pool.
*/
private static CommunicationThreadPool instance = null;
/**
* For locking purposes.
*/
private static Object semaphore = new Object();
/**
* Number of threads in this pool.
*/
private static final int THREAD_COUNT = 8;
/**
* Constructor for CommunicationThreadPool.
*/
private CommunicationThreadPool() {
super(THREAD_COUNT);
}
/**
* This pool has only one instace.
*
* @return the single instace of this <code>CommunicationThreadPool</code>
*/
public static CommunicationThreadPool instance() {
if (instance == null) {
synchronized (semaphore) {
if (instance == null) {
instance = new CommunicationThreadPool();
}
}
}
return instance;
}
/**
* Called by <code>ServerThread</code>S which we are listening for.
* Is responsible for signaling the gui thread to update the gui and
* signaling the task to unlock its view.
*
* @param s the <code>ServerThread</code> which has it's task finished.
*/
public void taskReady(ServerThread s) {
super.taskReady(s);
try{
JKFEventQueue.invokeAndWait(s.getTask());
} catch(Exception ex) {
ex.printStackTrace();
JKFClientLogger.error(ex.getMessage(), ex);
} finally {
s.getTask().stop();
}
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?