• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

will file reading use up jvm or memory?

 
Ranch Hand
Posts: 129
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I'm kind of obsessed with any resource taking up memory or anythign in the jvm if i devlop any custom-based application. if anything wrong happens i'd be blamed for the problem.

This time , i just developed a jsp file that reads a text file (which is a log) and everytime the user refreshes the entire log file is displayed.

My question is: will file reading everytime hinder the performance of the or memory or jvm? i don't think the cpu would be involved.

What i do is just declare a buffered reader, read the file, split it into chunks according to time and then print it with a loop. This will happen everytime the user refreshes.


CHeck out this code: what should i be afraid of?

 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

My question is: will file reading everytime hinder the performance of the or memory or jvm? i don't think the cpu would be involved.



Obviously, reading a file will use up memory, I/O bandwidth and CPU time. But so will everything else you might do instead (e.g. caching the file contents), so just by that we can't really advise you.

Amongst the questions you should be asking yourself are: How often does this page get accessed? If it's just once an hour or so it doesn't seem worth the effort to worry about this. If it gets accessed every few seconds it would be a different story.

Whether caching will help depends on how often the file changes. How often would the page get accessed between changes? If caching only saves a couple of reads between changes, it's probably not worthwhile doing. On the other hand, if you can serve the cached dozens (or even hundreds) of times between changes, it would be a different story.

If you really wanted to worry about object creation, you could cache the date-related strings (year, month, day, formattedMonth, fileAbsolute), since they only change every 24 hours. You could have a background thread change those automatically at midnight every day. But, again, whether that's worthwhile depends on how often the page is accessed.

From a design point of view, I wouldn't do I/O in a JSP, but use a servlet or backing bean instead. Scriptlets in JSP are considered bad design anyway.
 
Ali Khalfan
Ranch Hand
Posts: 129
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hey ulf,

i agree, jsps in files are crappy design. thing is this is i have no control over the application. it's the vendor's application and i'm just trying to make the log more accessible and available to a few operators. So i might let them access it every while (say 15-20 mins) JSP page is kind of the safest way i guess just to keep it in one page and avoid touching the web.xml or any other file.



anyway,

how does caching work?
how do i refresh a page with caching?
 
author & internet detective
Posts: 41860
908
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Ali Khalfan:
i agree, jsps in files are crappy design. thing is this is i have no control over the application.


You have some control - you are allowed to edit a JSP. Why not create a new jar with your code and have the JSP call that? This approach would allow you to introduce new, clean, well designed code while not requiring other changes to the existing app.


how does caching work?
how do i refresh a page with caching?


Caching is where you store data in memory. You would store it in a static variable and only read from the file after X minutes have passes. (Please, please, please don't do this in a JSP. Code in a JSP is bad enough - static variables are even worse.)

It sounds like there might be some premature optimization going on here. Have you demonstrated a performance problem reading the file each time? How long does that take? How big is the file?
 
Ali Khalfan
Ranch Hand
Posts: 129
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi Jeanne,

on any given date i doubt the file will exceed 500 kb. i'm not afraid of the performance of this particular script, but of the entire system ( alot of transactions occur on it)

Let's say i use caching how would i update the date when the new day occurs.
 
Jeanne Boyarsky
author & internet detective
Posts: 41860
908
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Ali Khalfan:
i'm not afraid of the performance of this particular script, but of the entire system ( alot of transactions occur on it)


You could always use a profiler to see if you have enough CPU or memory to spare. I'm not that clear on why you are considering caching if you have a memory issue - caching uses a lot of memory.


Let's say i use caching how would i update the date when the new day occurs.


A typical cache method looks like:
 
reply
    Bookmark Topic Watch Topic
  • New Topic