I know that sleep should be available in a static context. However, I need more resources so that I can protect this management. Most of the legacy codes that I'm processing now use the new Thread (). Sleep instead of Thread.sleep.
How bad is that?
for (int c = 0; c < 5; c++) {
new Thread().sleep(5000);
}
compared to this?
for (int c = 0; c < 5; c++) {
Thread.sleep(5000);
}
EDIT:
final long start = System.currentTimeMillis();
System.out.println("Total memory: " + Runtime.getRuntime().totalMemory());
System.out.println("Free memory: " + Runtime.getRuntime().freeMemory());
System.out.println("===========================");
for (int c = 0; c < 5; c++) {
new Thread().sleep(5000);
System.out.println("Used memory: " + (Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory()));
System.out.println("===========================");
}
System.out.println("Total memory: " + Runtime.getRuntime().totalMemory());
System.out.println("Free memory: " + Runtime.getRuntime().freeMemory());
System.out.println("===========================");
System.out.println("Time elapsed: " + (System.currentTimeMillis() - start) + " milliseconds");
Result (new thread (). Sleep):
Total memory: 5177344
Free memory: 4990904
Used memory: 186440
Used memory: 205136
Used memory: 205136
Used memory: 205136
Used memory: 205136
Total memory: 5177344
Free memory: 4972208
Time elapsed: 24938 milliseconds
Result (Thread.sleep):
Total memory: 5177344
Free memory: 4990904
Used memory: 186440
Used memory: 186440
Used memory: 204848
Used memory: 204848
Used memory: 204848
Total memory: 5177344
Free memory: 4972496
Time elapsed: 24938 milliseconds
source
share