473,320 Members | 1,732 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Access a servlets data in a non-servlet, threading?

Hello,

I am looking for a solution to update a .jsp page (kind of progress bar) which shows current progress in a huge simulation when users have to wait for longer periods and the way to do it was have the jsp page refresh often and the page data update by a bean containing the properties file details. The main servlet class continously running on the server regularly updates the properties file.

I am currently using a properties file, which is updated by property IO methods load() and store() which is then accessed by a non-servlet class to read and perform specific actions. Potential problems could be when reading and writing into properties file by two different sources at the same time. Another bigger problem is this works only for one user. This cannot be used by multi-user as the properties file cannot be instantiated/shared unlike a servlet.

The problem is that there cannot be a session or application scoped variable that can be shared between a servlet and non-servlet easily and hence a lack of easier way of communicating with each other.

Any other good solutions to such problems?? Can we add a thread in a servlet which allows us to access a particular variable value in the servlet anywhere else?

Thanks in advance.

Subject: How do we share data between a servlet and a non-servlet when you want to access data that changes in time?
Feb 19 '08 #1
3 1548
chaarmann
785 Expert 512MB
If more than one program access the properties file at the same time, (and especially if these programs do not run inside the same JVM, but are independent as in your case), you can use file-locks for synchronization.

(If they run inside the same JVM, you could simply declare the static methods "synchronized" or use a semaphore)

How to synchronize access with file-locks:
The writer process first creates an empty file "writeLock" (preferably in a temp directory) and flushes the write-cache. Then it iteratively reads the temp directory until it cannot find any "reading*" files there anymore.Then it modifies the desired properties file. After that it deletes the "writeLock" file.
Each one of the reader processes first searches for the "writeLock" file and waits until it's not there anymore. Then this reader process X creates an empty file "readingX" and starts reading this file. before it finishes, it deletes this file "readingX".

By the way,
you should consider using Ajax instead of a jsp-page-refresh; it's much faster and user-friendly.
Feb 19 '08 #2
Thanks you for your suggestion,

Unfortunately, this becomes a single user solution. I am unable to find a way to implement this in a multi-user application. Obviously, I cannot create a temporary file for each new user (new session but same JVM?) and have that new file also synchronized between a servlet and a non-servlet.

I am still looking at other solutions as I know many have already implemented this and I am eager to explore an alternative intuitive approach to this problem of multiple users.

Cheers
Krishna
Mar 24 '08 #3
Thanks you for your suggestion,

Unfortunately, this becomes a single user solution. I am unable to find a way to implement this in a multi-user application. Obviously, I cannot create a temporary file for each new user (new session but same JVM?) and have that new file also synchronized between a servlet and a non-servlet.

I am still looking at other solutions as I know many have already implemented this and I am eager to explore an alternative intuitive approach to this problem of multiple users.

All I need to display is the status of the current process, lets say there are a million records of five different files to be processed by a servlet, I have to show the user atleast as a percentage of records processed for each file every couple of seconds while the process is continuing at the server side.


Cheers
Krishna
Mar 24 '08 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Yoandy Rodriguez | last post by:
I'm developing a J2EE aplication and the project leader told me to investigate about the Data Access Object design pattern. I did some research at Sun's blueprints for the enterprise site but there...
1
by: Don Khan | last post by:
Hi, I am relatively new to JAVA but I am trying to build contact management system which would allow users to create their list of contacts. The contact data would be in database and security is...
11
by: Roger Leigh | last post by:
The C++ book I have to hand (Liberty and Horvath, Teach yourself C++ for Linux in 21 Days--I know there are better) states that "static member functions cannot access any non-static member...
49
by: Yannick Turgeon | last post by:
Hello, We are in the process of examining our current main application. We have to do some major changes and, in the process, are questionning/validating the use of MS Access as front-end. The...
5
by: deko | last post by:
I have a number of users with the same Access app on each of their laptops. When users have internet access, they want to be able to synchronize records in their individual databases with a main...
17
by: Mell via AccessMonster.com | last post by:
Is there a way to find out where an application was created from? i.e. - work or home i.e. - if application sits on a (work) server/network, the IT people know the application is sitting...
3
by: AaronMason | last post by:
Hi, Is it possible to use SQL to get a database's structure, like SHOW TABLES in MySQL? I'd like to create a database access interface for MS Access databases in JSP/Java Servlets and I need to...
8
by: Sid | last post by:
I hope someone could help me with this. I am trying to setup a criteria to decide when to allow/not allow user to click on the check box. logically it looks simple but I am not able to...
1
by: harithagowd | last post by:
how to access the immage in servlets which is stored in the same root directory
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.