This file contains 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
ThreadPoolExecutor pool = new ThreadPoolExecutor(5, 5, 0L, TimeUnit.MILLISECONDS, new LinkedBlockingQueue<Runnable>(2500)); | |
pool.setRejectedExecutionHandler(new ThreadPoolExecutor.CallerRunsPolicy()); | |
AsynchronousFileChannel outputfile = | |
AsynchronousFileChannel.open(Paths.get(FILE_NAME), | |
new HashSet<StandardOpenOption>(Arrays.asList(StandardOpenOption.WRITE, | |
StandardOpenOption.CREATE)), pool); |
This file contains 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
/** | |
* A class that calculates the optimal thread pool boundaries. It takes the desired target utilization and the desired | |
* work queue memory consumption as input and retuns thread count and work queue capacity. | |
* | |
* @author Niklas Schlimm | |
* | |
*/ | |
public abstract class PoolSizeCalculator { | |
/** |
This file contains 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
public class Performance_Benchmark_AsynchronousFileChannel_2 implements Runnable { | |
private static AsynchronousFileChannel outputfile; | |
private static AtomicInteger fileindex = new AtomicInteger(0); | |
private static ThreadPoolExecutor pool = new ThreadPoolExecutor(1, 1, 0L, TimeUnit.MILLISECONDS, | |
new LinkedBlockingQueue<Runnable>(), new ThreadFactory() { | |
@Override | |
public Thread newThread(Runnable r) { | |
Thread t = new Thread(r); | |
t.setDaemon(true); |
This file contains 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
Exception in thread "main" java.lang.OutOfMemoryError: unable to create new native thread | |
at java.lang.Thread.start0(Native Method) | |
at java.lang.Thread.start(Thread.java:691) | |
at java.util.concurrent.ThreadPoolExecutor.addWorker(ThreadPoolExecutor.java:943) | |
at java.util.concurrent.ThreadPoolExecutor.execute(ThreadPoolExecutor.java:1336) | |
at sun.nio.ch.AsynchronousChannelGroupImpl.executeOnPooledThread(AsynchronousChannelGroupImpl.java:188) | |
at sun.nio.ch.PendingIoCache.clearPendingIoMap(PendingIoCache.java:158) | |
at sun.nio.ch.PendingIoCache.close(PendingIoCache.java:115) | |
at sun.nio.ch.WindowsAsynchronousFileChannelImpl.close(WindowsAsynchronousFileChannelImpl.java:147) | |
at com.schlimm.java7.nio.Performance_OOM_AsynchronousFileChannel_1.main(Performance_OOM_AsynchronousFileChannel_1.java:36) |
This file contains 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
public class Performance_Benchmark_AsynchronousFileChannel_2 implements Runnable { | |
private static AsynchronousFileChannel outputfile; | |
private static AtomicInteger fileindex = new AtomicInteger(0); | |
private static ExecutorService pool = Executors.newFixedThreadPool(1, new ThreadFactory() { | |
@Override | |
public Thread newThread(Runnable r) { | |
Thread t = new Thread(r); | |
t.setDaemon(true); | |
return t; |
This file contains 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
public class ThreadPool { | |
... | |
private static final ThreadFactory defaultThreadFactory = new ThreadFactory() { | |
@Override | |
public Thread newThread(Runnable r) { | |
Thread t = new Thread(r); | |
t.setDaemon(true); | |
return t; | |
} | |
}; |
This file contains 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
public class Performance_Benchmark_ConventionalFileAccessExample_1 implements Runnable { | |
private static FileOutputStream outputfile; | |
private static byte[] content = "Hello".getBytes(); | |
public static void main(String[] args) throws InterruptedException, IOException { | |
try { | |
System.out.println("Test: " + Performance_Benchmark_ConventionalFileAccessExample_1.class.getSimpleName()); | |
outputfile = new FileOutputStream(new File("E:/temp/afile.out"), true); | |
Average average = new PerformanceHarness().calculatePerf(new PerformanceChecker(1000, new Performance_Benchmark_ConventionalFileAccessExample_1()), 5); |
This file contains 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
public class Performance_Benchmark_AsynchronousFileChannel_1 implements Runnable { | |
private static AsynchronousFileChannel outputfile; | |
private static int fileindex = 0; | |
public static void main(String[] args) throws InterruptedException, IOException { | |
try { | |
System.out.println("Test: " + Performance_Benchmark_AsynchronousFileChannel_1.class.getSimpleName()); | |
outputfile = AsynchronousFileChannel.open(Paths.get("E:/temp/afile.out"), StandardOpenOption.WRITE, | |
StandardOpenOption.CREATE, StandardOpenOption.DELETE_ON_CLOSE); |
This file contains 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
public class CallGraph_Default_AsynchronousFileChannel { | |
private static AsynchronousFileChannel fileChannel; | |
public static void main(String[] args) throws InterruptedException, IOException, ExecutionException { | |
try { | |
fileChannel = AsynchronousFileChannel.open(Paths.get("E:/temp/afile.out"), StandardOpenOption.READ, | |
StandardOpenOption.WRITE, StandardOpenOption.CREATE, StandardOpenOption.DELETE_ON_CLOSE); | |
Future<Integer> future = fileChannel.write(ByteBuffer.wrap("Hello".getBytes()), 0L); | |
future.get(); |
This file contains 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
Constant pool: | |
#1 = Class #2 // com/schlimm/bytecode/examples/BytecodeExamples | |
... | |
#42 = Class #43 // java/lang/String | |
... | |
#65 = Methodref #42.#66 // java/lang/String.length:()I | |
#66 = NameAndType #67:#68 // length:()I | |
#67 = Utf8 length | |
#68 = Utf8 ()I | |
... |