*
The moose likes Threads and Synchronization and the fly likes Thread & Files Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Threads and Synchronization
Bookmark "Thread & Files" Watch "Thread & Files" New topic
Author

Thread & Files

Ramesh VR
Greenhorn

Joined: Jan 17, 2006
Posts: 1
Is it feasible to read same Unix text file from different start locations using threads?
I have a scenario to read all the lines of a line (few thousand lines) into ArrayList parse, validate & load into tables.
Will it become faster / slower if I implement multi threading for reading & populating the ArrayList?
Saifuddin Merchant
Ranch Hand

Joined: Feb 08, 2009
Posts: 597

Is it feasible to read same Unix text file from different start locations using threads?
Yes, I don't see why not

A few thousand lines is not much when it comes to reading. Reading in parallel wont help much (in this case) - I guess for optimization the first thing is to see if the simple solution has a performance bottle neck and then look for spots that are impacting performance.

Premature optimization is the root of all evil in programming.


Cheers - Sam.
Twisters - The new age Java Quiz || My Blog
Sergey Babkin
author
Ranch Hand

Joined: Apr 05, 2010
Posts: 50
Ramesh VR wrote:Is it feasible to read same Unix text file from different start locations using threads?
I have a scenario to read all the lines of a line (few thousand lines) into ArrayList parse, validate & load into tables.
Will it become faster / slower if I implement multi threading for reading & populating the ArrayList?


On Unix itself the system call is pread(). Yes, it can be done faster by multithreading, if the bottleneck is in the CPU processing and not in the disk reading time.

BTW,, the fastest way at all is to use mmap() to map the file into the process memory. But it doesn't work too well with the very large files, that are larger than the address space.
Saifuddin Merchant
Ranch Hand

Joined: Feb 08, 2009
Posts: 597

pread(), mmap() Java. I did not quite catch the connection on how they would work together?
Sergey Babkin
author
Ranch Hand

Joined: Apr 05, 2010
Posts: 50
Sam Mercs wrote:pread(), mmap() Java. I did not quite catch the connection on how they would work together?


Probably won't :-) But since the question was about Unix...
 
 
subject: Thread & Files
 
Similar Threads
replacing content in a file
Extract data from text file
Convert String to multiline InputStream
How to declare an array without specifying its size?
Problem returning serialized CachedRowSetImpl in servlet