File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Single threaded to multi-threaded design

 
Srinivasa Raghavan
Ranch Hand
Posts: 1228
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
We have got a FTP processes that moves data from Linux to NT.
It's now designed as a single threaded application.
In near future we are likely to get more number of files for FTP'ing.
Is there any design pattern or could any one tell me a good design,
to convert this application as a multi-threaded one. so that the files can be ftp'd as soon as it comes to Linux.
 
Ilja Preuss
author
Sheriff
Posts: 14112
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What do you hope to gain from multi-threading? Isn't the transfer likely to be bounded by network bandwith?
 
Srinivasa Raghavan
Ranch Hand
Posts: 1228
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What I thought was, by going though a multithreaded design, we can ftp multiple files at the same time. Each thread would take care of FTP'ing group of files and move it to a backup folder.

Is that not good ? Am I going wrong ?
 
Guy Allard
Ranch Hand
Posts: 776
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Srinivasa - You are not way off base with this idea. Multi-threading will help offset network IO wait times (unless your net is already saturated).

I do this frequently with network (not FTP) transfers.

You will gain throughput: files/second or bytes/second or however you are measuring it.

You must experimentally determine the "best" value for the maximum number of threads. Too many can hurt rather than help.

Guy
 
Jeevan Philip
Ranch Hand
Posts: 41
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Java 5 Executor Interface and related concurrent APIs should help you out in designing the same. The intention of Executor Class is as follows...

This interface provides a way of decoupling task submission from the mechanics of how each task will be run, including details of thread use, scheduling, etc


It also provides convenient implementations for creating various types of thread pools. see the links below.

http://java.sun.com/j2se/1.5.0/docs/guide/concurrency/overview.html
http://java.sun.com/j2se/1.5.0/docs/api/java/util/concurrent/Executor.html
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic