Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / December 2005

Tip: Looking for answers? Try searching our database.

InputStream vs. SocketChannel performance?

Thread view: 
Daisy - 02 Dec 2005 14:21 GMT
I'm trying to improve the performance of some Java that someone else
wrote.  This code uses SocketChannel's read() method.  I'm considering
rewriting the code using InputStream (which I know is fast) to improve
performance.  I'd appreciate the experience and opinions of others to
help me decide whether to rewrite.

Is SocketChannel's read() method much more time consuming than
InputStream's read()?
Chris Smith - 02 Dec 2005 16:05 GMT
> I'm trying to improve the performance of some Java that someone else
> wrote.  This code uses SocketChannel's read() method.  I'm considering
[quoted text clipped - 4 lines]
> Is SocketChannel's read() method much more time consuming than
> InputStream's read()?

There is unlikely to be any visible difference whatsoever in the read
operation.  How you use the resulting data, though, could yield
performance differences.  For example, if you user SocketChannel and
then immediately copy the results from a ByteBuffer into a byte[], then
that copy could be expensive for large amounts of data.

In the end, though, I'd expect that waiting on the socket itself would
swamp any performance issues you'd get in code, unless this is a socket
connected to localhost.

Signature

www.designacourse.com
The Easiest Way To Train Anyone... Anywhere.

Chris Smith - Lead Software Developer/Technical Trainer
MindIQ Corporation

Thomas Weidenfeller - 02 Dec 2005 16:43 GMT
> I'm trying to improve the performance of some Java that someone else
> wrote.  This code uses SocketChannel's read() method.  I'm considering
> rewriting the code using InputStream (which I know is fast) to improve
> performance.

First things first. Did you run a profiler to confirm this is indeed the
bottleneck in the application? If not, do that first.

/Thomas
Signature

The comp.lang.java.gui FAQ:
ftp://ftp.cs.uu.nl/pub/NEWS.ANSWERS/computer-lang/java/gui/faq
http://www.uni-giessen.de/faq/archiv/computer-lang.java.gui.faq/



Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.