Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Thread & Files

 
Ramesh VR
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 607
Firefox Browser Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Sergey Babkin
author
Ranch Hand
Posts: 50
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 607
Firefox Browser Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
pread(), mmap() Java. I did not quite catch the connection on how they would work together?
 
Sergey Babkin
author
Ranch Hand
Posts: 50
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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...
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic