日期:2014-05-16 浏览次数:20614 次
/** * Bootstrap class for lauching a JPPF node. The node class is dynamically loaded from a remote server. * @author Laurent Cohen */ public class NodeRunner { //*************** /** * Set a persistent object with the specified key. * @param key the key associated with the object's value. * @param value the object to persist. */ public static synchronized void setPersistentData(Object key, Object value) { persistentData.put(key, value); } /** * Get a persistent object given its key. * @param key the key used to retrieve the persistent object. * @return the value associated with the key. */ public static synchronized Object getPersistentData(Object key) { return persistentData.get(key); } /** * Remove a persistent object. * @param key the key associated with the object to remove. * @return the value associated with the key, or null if the key was not found. */ public static synchronized Object removePersistentData(Object key) { return persistentData.remove(key); } //****************** }
public class XXXXXXXXXTask extends JPPFTask{ private static final String DATA_SOURCE_KEY = "dataSource"; public void run() { DataSource dataSource = (DataSource) NodeRunner.getPersistentData(DATA_SOURCE_KEY); XXXXXService service = null; if (dataSource == null) { dataSource = new DriverManagerDataSource("com.mysql.jdbc.Driver", "jdbc:mysql://192.168.1.90:3306/xxxx?useUnicode=true&characterEncoding=UTF-8", "xxx", "xx"); service = new XXXXXService(); service.setDataSource(dataSource); NodeRunner.setPersistentData(DATA_SOURCE_KEY); ///// Process the task using the Service build from the dataSource.///////// } }