Only 49 hours left in the trailboss' kickstarter!

New rewards and stretch goals. CLICK HERE!



  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Performance on load File using InputStream by getResourceAsStream/ByteArrayInputStream  RSS feed

 
Muralidharan Kandasamy
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a query on the performance for IO. I was loading the file using the

InputStream myString = MyClass.class.getResourceAsStream("filePath");

But this was called everytime through the multiple threads, instead of reloading the file everytime, I converted the file into String. And then passing that string to each threads. Inside the thread it'll be loading the InputStream using the

Inside Thread
InputStream schema = new ByteArrayInputStream(myString.getBytes("UTF-8"));

So the idea is, instead of loading the file everytime, load the file once on the main class, and pass the string to each thread to load the inputStream.

Will this really help to improve the performance. Please suggest.
 
Paul Clapham
Sheriff
Posts: 22185
38
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That depends on what aspects of "performance" you are interested in. For such a specific example I think the best thing for you to do is to try it both ways (it looks like a simple change) and evaluate the two options based on your notion of "performance".
 
Paul Clapham
Sheriff
Posts: 22185
38
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You might find you got even better performance if you just loaded the file once into some data structure, and then shared that data structure among the threads. But again, you might not.
 
Ank Sri
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Not sure why would you do this because you again are passing the InputStream to all the threads which would again either process the bytes or the String by reading the Stream so why not just pass the String or the bytes to all the threads. That would definitely get you some performance gain and also would not create so many InputStream objects and thus help you keep your memory requirement low.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!