Archive

Posts Tagged ‘copy’

Processing files over network slows down programs — Part 2

January 24th, 2008 Arun Manivannan No comments

There are a few other things i wanted to share. I actually use the java.util.concurrent.ThreadPoolExecutor to copy files. For those using Java 1.4, here is your gateway to concurrency :  http://backport-jsr166.sourceforge.net/

Here goes my ThreadPool code. You surely could write better code than this.

LinkedBlockingQueue archiverTaskQueue = new LinkedBlockingQueue();
ThreadPoolExecutor archiverExecutor = new ThreadPoolExecutor(50, MAXTHREADS, 50000L, TimeUnit.MILLISECONDS,archiverTaskQueue);
File tempCurrentFile=new File(tempDestinationDir, archiveFileName);
archiver = new Archiver(tempCurrentFile, new File(actualDestinationDir, fileName));
archiverExecutor.execute(archiver);
 

Forgot to mention, I use NIO to copy files. I understand that there are people for and against NIO. My reason for using NIO is just it sounded exciting.

Source code : Archiver.java