Created
October 16, 2013 17:02
-
-
Save maxdeliso/7011210 to your computer and use it in GitHub Desktop.
funthread.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class FunThread extends Thread { | |
Object first[]; | |
Object second[]; | |
int size; | |
public FunThread(Object _first[], Object _second[], int _size) { | |
first = _first; | |
second = _second; | |
size = _size; | |
} | |
public void run() { | |
/* System.out.println("copying " + size + | |
" on thread " + Thread.currentThread() + " from " + | |
first + " to " + second);*/ | |
if(first.hashCode() == second.hashCode()) { | |
System.exit(1); | |
} | |
Thread.yield(); | |
System.arraycopy(first, 0, second, 0, size); | |
} | |
} | |
class Fun { | |
static int MEM_PRINT_INT = 100; | |
static int NUM_PAR_THREADS = 8; | |
static int NUM_LEN_INC = 1; | |
static int INC_BYTES = 32; | |
public static void main(String[] args) { | |
int len = INC_BYTES; | |
for(int i = 0;;i++) { | |
Object[] sObj = new Object[len]; | |
Object[] dObj = new Object[len]; | |
for(int j = 0; j < NUM_PAR_THREADS; ++j) { | |
FunThread ft = new FunThread(sObj, dObj, len); | |
ft.start(); | |
} | |
System.gc(); | |
if(i % MEM_PRINT_INT == 0) { | |
System.out.println(Runtime.getRuntime().freeMemory() + "b free"); | |
} | |
if(i % NUM_LEN_INC == 0) { | |
len += INC_BYTES; | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment