0

How to use a COMMON session attribute ??

asked 2008-11-19 13:51:51 +0800

erdem gravatar image erdem
57

hi all,

i am using a chat application and different users could be online at the same time and also i want to show the online people who are in chat now.. I think to put all users names or id's at a same session attribute..
How can i define a global session attribute or another way ??

delete flag offensive retag edit

2 Replies

Sort by ยป oldest newest

answered 2008-11-19 14:01:40 +0800

ziccardi gravatar image ziccardi
321 7

updated 2008-11-19 14:01:58 +0800

Could it be ok for you to simply declare a static member variable inside a class?

Something like this:


public class SharedVariables
{

   public static Map m_mUsers = new HashMap();

  public static synchronized void addLoggedinUser(String sUser)
  {
      m_mUsers.put(sUsers, new Date());
  }

  public static synchronized void removeLoggedinUser(String sUser)
  {
       m_mUsers.remove(sUsers);
  }

}

Of course, you have to synchronize the map.

link publish delete flag offensive edit

answered 2008-11-19 14:07:33 +0800

erdem gravatar image erdem
57

thx ziccardi,

it think "public static" corresponds what i need...

link publish delete flag offensive edit
Your reply
Please start posting your answer anonymously - your answer will be saved within the current session and published after you log in or create a new account. Please try to give a substantial answer, for discussions, please use comments and please do remember to vote (after you log in)!

[hide preview]

Question tools

Follow

RSS

Stats

Asked: 2008-11-19 13:51:51 +0800

Seen: 145 times

Last updated: Nov 19 '08

Support Options
  • Email Support
  • Training
  • Consulting
  • Outsourcing
Learn More