[jboss-user] [JBoss Portal] - Sharing a data among different browser instances

krishan do-not-reply at jboss.com
Wed Sep 6 06:55:54 EDT 2006


Hi,

I am using JBoss portal 2.4,

I have defined a singleton class as follows and copied into the "jboss/server/default/lib" to be used for all the other portlets,

package testcom;

public class Communication {	
	private static Communication instance = null;
	private static String sName = "Krishan";

	private Communication(String sName)
	{
		this.sName =sName;
	}	
	
	public String getName()
	{
		return this.sName;
	}
	
	public void setName(String pName)
	{		
		this.sName = pName;
	}
	
	 public static Communication getInstance(String pCaller) {
		 if(instance == null) {
			 String sureName ="Fernando";
	         instance = new Communication(sureName);
	         System.out.println("********************************instance is null");
	      }
		 
		 System.out.println("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~pCaller::sName:"+sName+"::"+pCaller);
		 
	     return instance;
	   	}	
}


In my first senario:

When I access it for the very first time 
as http://localhost:8080/portal, it created a new  "Communication" instance.

 Communication cm = Communication.getInstance("MyPortlet");           
  writer.write("cm.getName():"+cm.getName());  
  cm.setName("Pradeep");
  writer.write("cm.getName():"+cm.getName());  


I got the Name as I expected: 
  cm.getName():Fernando 
  cm.getName():Pradeep

and also when I open another browser instance, I got the following result as expected.
  cm.getName():Pradeep
  cm.getName():Pradeep

But in my second scenario, When I click on the different portlet Url Tab in the same browser instance which is also suppose to display the cm.getName(),

it created the new Communication instance and  give me the following result,
cm.getName():Fernando 

But I was expected following results with out getting creating a new  Communication instance ;
   cm.getName():Pradeep

I noticed that the url I clicked is contain with the session id values as follows,

http://localhost:8080/portal/portal/default/IPC;jsessionid=E5FE54B2057947FC8E77F0D57066F16F

So could you please tell me how can I get the expected data value without get creating another instance of a Communication object.(I want it to behave as a singleton object)

Thanks,
Krishan




View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=3969685#3969685

Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=3969685



More information about the jboss-user mailing list