/* * Created on Dec 30, 2005 * * To change the template for this generated file go to * Window>Preferences>Java>Code Generation>Code and Comments */ package samplecode; /** * @author Headley Williamson * Threaded Hash * www.greattastingjava.com code licensed under http://creativecommons.org/licenses/by/2.5/ */ public class HWThreadedHashExample extends HWThread{ String name; int count; int sleeptime; HWThreadedHashExample(String p_name, int p_count, int p_sleeptime) throws Exception { name = p_name; count = p_count; sleeptime = p_sleeptime; } public void run() { System.out.println("Name:"+name+"->START"); try { for (int i=0; i"+i); Thread.sleep(sleeptime); } } catch (Exception ex) { setException(ex); } System.out.println("Name:"+name+"->END"); setData(name +" data"); setFinished(true); } public static void main(String[] args) throws Exception{ HWThreadedHash threadhash = new HWThreadedHash(10); HWThreadedHashExample thread1 = new HWThreadedHashExample("Thread1",10,1000); HWThreadedHashExample thread2 = new HWThreadedHashExample("Thread2",15,1000); HWThreadedHashExample thread3 = new HWThreadedHashExample("Thread3",1,1000); threadhash.put("thread1", thread1); threadhash.put("thread2", thread2); threadhash.put("thread3", thread3); String data = (String) threadhash.get("thread3"); System.out.println(data); data = (String) threadhash.get("thread2"); System.out.println(data); data = (String) threadhash.get("thread1"); System.out.println(data); } }