From: Pavel V. <va...@us...> - 2002-03-13 21:10:08
|
Update of /cvsroot/javaprofiler/test/snapshot In directory usw-pr-cvs1:/tmp/cvs-serv18430 Modified Files: TestNoSwing.java Log Message: thread added Index: TestNoSwing.java =================================================================== RCS file: /cvsroot/javaprofiler/test/snapshot/TestNoSwing.java,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -r1.3 -r1.4 *** TestNoSwing.java 3 Mar 2002 00:26:30 -0000 1.3 --- TestNoSwing.java 13 Mar 2002 21:10:04 -0000 1.4 *************** *** 41,66 **** class TestNoSwing { ! ! Set set; ! List list; TestNoSwing() { set = new HashSet(); ! list = new ArrayList(); }; ! void initSet() { int i; ! ! for (i = 1; i < 500; i++) { set.add( new Double(Math.random()) ); } ! }; ! ! void initList() { Iterator it=set.iterator(); Double d; ! ! while ( it.hasNext() ) { d = (Double) it.next(); --- 41,72 ---- class TestNoSwing { ! final int numIter = 50; ! final int numItems = 1000; ! private Set set; ! private List list; ! ! //shared ! SortedSet tree; TestNoSwing() { set = new HashSet(); ! list = new LinkedList(); ! tree = new TreeSet(); }; ! void init() { int i; ! ! //init set ! set.clear(); ! for (i = 1; i < numItems; i++) { set.add( new Double(Math.random()) ); } ! ! //init list Iterator it=set.iterator(); Double d; ! ! list.clear(); while ( it.hasNext() ) { d = (Double) it.next(); *************** *** 70,81 **** void sort() { - SortedSet tree=new TreeSet(); Iterator it=list.iterator(); Double d; - while ( it.hasNext() ) { d = (Double) it.next(); ! tree.add( d ); } --- 76,85 ---- void sort() { Iterator it=list.iterator(); Double d; while ( it.hasNext() ) { d = (Double) it.next(); ! sortingAdd( d ); } *************** *** 85,93 **** //System.out.print( d + " "); } ! } public static void main( String[] arg ) { TestNoSwing a = new TestNoSwing(); int i; --- 89,172 ---- //System.out.print( d + " "); } ! } ! ! void work() { ! int i; ! ! for (i = 1; i < numIter; i++) { ! init(); ! sort(); ! if ( Math.round(i/10) - i/10 == 0 ) ! clear(); ! System.err.print( i + " " ); ! } ! } ! ! synchronized void sortingAdd( Double d ) { ! tree.add( d ); ! } ! ! synchronized void clear() { ! tree.clear(); ! } ! ! /////////////////////////////////////////////////////////////////////// ! private class SortWorker extends Thread { ! private Set set; ! private List list; ! ! SortWorker() { ! set = new HashSet(); ! list = new LinkedList(); ! }; ! ! void init() { ! int i; ! ! //init set ! set.clear(); ! for (i = 1; i < numItems; i++) { ! set.add( new Double(Math.random()) ); ! } ! ! //init list ! Iterator it=set.iterator(); ! Double d; ! ! while ( it.hasNext() ) { ! d = (Double) it.next(); ! list.add( d ); ! } ! } ! ! void sortInv() { ! ListIterator it=list.listIterator(); ! Double d; ! ! //go to last ! while ( it.hasNext() ) { ! it.next(); ! }; ! ! while ( it.hasPrevious() ) { ! d = (Double) it.previous(); ! sortingAdd( d ); ! } ! } ! ! public void run () { ! int i; ! ! init(); ! for (i = 1; i < numIter; i++) { ! sortInv(); //make collision on sychronized method ! } ! } } + /////////////////////////////////////////////////////////////////////// public static void main( String[] arg ) { TestNoSwing a = new TestNoSwing(); + SortWorker b = a.new SortWorker(); //inner class creation int i; *************** *** 99,111 **** catch (IOException ioe) { System.err.println( "IOException caught:" + ioe ); } ! for (i = 1; i < 20; i++) { ! a.initSet(); ! a.initList(); ! a.sort(); ! System.err.print( i + " " ); ! } ! System.err.println( "end." ); System.err.print("Press a key"); --- 178,187 ---- catch (IOException ioe) { System.err.println( "IOException caught:" + ioe ); + ioe.printStackTrace(); } ! b.start(); ! a.work(); ! System.err.println( "end." ); System.err.print("Press a key"); *************** *** 115,119 **** --- 191,198 ---- catch (IOException ioe) { System.err.println( "IOException caught:" + ioe ); + ioe.printStackTrace(); } } } + + |