This week's book giveaway is in the Jobs Discussion forum.
We're giving away four copies of Java Interview Guide and have Anthony DePalma on-line!
See this thread for details.
The moose likes OO, Patterns, UML and Refactoring and the fly likes Single threaded to multi-threaded design Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Engineering » OO, Patterns, UML and Refactoring
Bookmark "Single threaded to multi-threaded design" Watch "Single threaded to multi-threaded design" New topic

Single threaded to multi-threaded design

Srinivasa Raghavan
Ranch Hand

Joined: Sep 28, 2004
Posts: 1228
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.

Thanks & regards, Srini
MCP, SCJP-1.4, NCFM (Financial Markets), Oracle 9i - SQL ( 1Z0-007 ), ITIL Certified
Ilja Preuss

Joined: Jul 11, 2001
Posts: 14112
What do you hope to gain from multi-threading? Isn't the transfer likely to be bounded by network bandwith?

The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
Srinivasa Raghavan
Ranch Hand

Joined: Sep 28, 2004
Posts: 1228
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

Joined: Nov 24, 2000
Posts: 776
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.

Jeevan Philip
Ranch Hand

Joined: Nov 17, 2006
Posts: 41
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.
I agree. Here's the link:
subject: Single threaded to multi-threaded design
It's not a secret anymore!