Solved

Contact across sessions

Posted on 2003-10-31
6
199 Views
Last Modified: 2010-04-01
Hi!

I am designing (and soon implementing) a web-application (mysql-tomcat-jsp-struts).

The application deals with shift-planning, and there is two kinds of users: "regular" and "boss". The users are working in teams, and a typical team counts approx. 10 regular users and one boss.

The boss-users can alter some settings (restrictions and other rules) that apply for all the regular users on his team.

The way the application is designed right now, an object "SystemVariables" is loaded from MySQL with the relevant settings for the team (as mentioned, these settings are made by boss-users), and is stored in Session when the user logs in. This way it is not neccesary to consult the DB each time you need a setting in fx an ActionClass.

My problem is, that I am not sure if this is good approach! If a boss-user changes some settings, all the users that are logged in at that time will NOT be affected before they log in next time.

1) Is there a way that one session (the boss-session) can "contact" the other active sessions, and tell them to reload their settings?

2) Alternatively I COULD of course reload system-settings in the beginning of each Action-class, but this seems a bit clumsy. What do you think about that?

Kind regards,

Nic
0
Comment
Question by:JNic
  • 4
  • 2
6 Comments
 
LVL 14

Expert Comment

by:kennethxu
ID: 9660442
>> My problem is, that I am not sure if this is good approach!
NO, and your question followed right after this actually tells youself it is not.

The right approach depends on your other requirements.

1. as you already know, read database in every request. and you know pros and cons.

2. if you know that your application will never be clustered. use context bag instead of session bag. You only store group name in session, which will never change, and store a map in servlet context (or in another word, application scope). the map will be indexed by group name and value your SystemVariables object.

3. if you need cluster, you'll have to implement your SystemVariables as EJB, it should be an Entity Bean and the primary key will be group name. In every action class, you consult EJB instead of database.

there are other possible approaches like use JMS and session, that will be over complicated and error prone.

Let us know.
0
 
LVL 14

Expert Comment

by:kennethxu
ID: 9660506
OK, I take 50% of my "NO" answer.
if you don't use cluster, option 2 is always the best approach. but if you do use cluster, there is another option besides 1 and 3 if your user can accept that the boss change will be delayed to take effect on currently logged in users. the idea is:

Store a long var 'updatetime' in session with SystemVariables. when you load SystemVariables from database, you set updatetime=System.currentTimeMillis();
in every action, you compare the updatetime with currentTimeMillis(), if it is more then, say 60 seconds, you'll read the SystemVariables from database again. this can greatly limit database access and also gets setting updated for logged in users.
0
 
LVL 1

Author Comment

by:JNic
ID: 9660780
Kenneth, it is SO nice to have you back! (You have been away a bit, havent you?)

Your answer is really helping a LOT, and it seems to me, that solution 2 is right for me. I dont know why I forgot everything about application scope... (blush)

But could you elaborate a little bit on the subject of "clustered applications"? Are you talking about applications that are running on multiple servers? Or/and  multiple DB's?

Kindest regards,

Nic
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 14

Accepted Solution

by:
kennethxu earned 125 total points
ID: 9664782
Thanks for your greeting! Yeah, a lot of things happened, change job, move house, get kid into school. You know that's a lot and sorry for being away for such a long while :-)

I meant "clustered applications" as j2ee web application deployed to a clustered j2ee application server. by specification, application scope objects are not replicated to clustered servers so it is only available to local server. For example,

J2ee Server A and B are clustered. webapp deployed to the cluster, so there will be 2 copies of you webapp running.
copyA in serverA and copyB in serverB
a user login and is routed to serverA
a boss login and is routed to serverB
boess change setting in serverB
user in serverA don't see the changes

let me know if you have futher enquires,
Ken
0
 
LVL 1

Author Comment

by:JNic
ID: 9665546
OK, - thas was what I thought it meant. :-)

For me, I am very sure that this scenario will never happen. The teams will always be stored on the same server.

Anyway- if this scenario would actually happen, I will be a millionaire and able to solve it! :) :) :)

Thanks a lot for your help!

Kindest regards,

Nicolai Krog (had to change username because I have a new e-mail.)
0
 
LVL 14

Expert Comment

by:kennethxu
ID: 9665868
As always, my pleasure!
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

This article was initially published on Monitis Blog, you can read it here . When it comes to deciding which approach to website performance monitoring is best for your business, unfortunately, like so many options in life . . . it depends. In t…
The Windows functions GetTickCount and timeGetTime retrieve the number of milliseconds since the system was started. However, the value is stored in a DWORD, which means that it wraps around to zero every 49.7 days. This article shows how to solve t…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

730 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question