RE: Doubt on lifecycle of a class in shared folder

2008-07-18 Thread java_is_everything

So, it means my code and intentions are alright, it's GWT that seems the
culprit, since I have not touched the default conf/properties file.


Regards
Ajay Garg


Caldarale, Charles R wrote:
 
 
 
 What, pray tell, is a static instance in Java terminology?
 
 If the class file of interest is being loaded by separate classloaders,
 then there will be separate java.lang.Class instances for each, despite
 originating from the same .class file.  However, the OP claims that the
 class is in the shared library, and should therefore be loaded by Tomcat's
 shared class loader - once.
 
 Since independent testing verifies the proper operation of a normally
 configured Tomcat, the OP's environment is either non-standard (e.g.,
 someone's been mucking around with conf/catalina.properties), or the
 framework is using its own classloader, or the OP doesn't really know
 where his classes are.
 
  - Chuck
 
 
 THIS COMMUNICATION MAY CONTAIN CONFIDENTIAL AND/OR OTHERWISE PROPRIETARY
 MATERIAL and is thus for use only by the intended recipient. If you
 received this in error, please contact the sender and delete the e-mail
 and its attachments from all computers.
 
 -
 To start a new topic, e-mail: users@tomcat.apache.org
 To unsubscribe, e-mail: [EMAIL PROTECTED]
 For additional commands, e-mail: [EMAIL PROTECTED]
 
 
 

-- 
View this message in context: 
http://www.nabble.com/Doubt-on-lifecycle-of-a-class-in-%22shared%22-folder-tp18502300p18526565.html
Sent from the Tomcat - User mailing list archive at Nabble.com.


-
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: Doubt on lifecycle of a class in shared folder

2008-07-17 Thread java_is_everything

Thanks for the reply.

Yes, I had ensured it (even did a double-check after your mail, everything
seems in place). But the problem persists. Everytime, webapp2 calls
x.getA(), a null is returned, which shouldn't be the case, since a is a
static variable.

I have done another test. What I have done is, open both the webapps in two
different windows. Call x.setA() from webapp1, and then call x.getA() from
webapp1 as well as webapp2. It's working fine in webapp1, but not in
webapp2-returning null. This clearly tells that ::

a) Both webapps get two different instances of x.class- pretty ok.
b) Each instance has a different instance of variable a, which SHOULD NOT
BE THE CASE, since a is static. 

Any lights in a dark tunnel ??

Ajay Garg

Konstantin Kolinko wrote:
 
 Make sure, that you do not have a copy of x.class in WEB-INF/classes
 or WEB-INF/lib/*.jar of any of your web applications. Those take
 precedence over shared or common classes.
 
 See
 http://tomcat.apache.org/tomcat-5.5-doc/class-loader-howto.html
 for details.
 
 
 2008/7/17 java_is_everything [EMAIL PROTECTED]:

 I am sorry. The methods setA() and getA() are static, Rest everything
 remains
 same.

 Regards
 Ajay Garg



 java_is_everything wrote:

 Hi all.

 I have placed two applications in the webapps folder, and calling a
 class,
 say 'x.java' placed in tomcat's shared folder. x.java is of the
 following
 config :


 
 public class x
 {
 public static int a;

 static
 {
 System.out.println(Static things initializing !!);
 }

 public void setA(int aa)
 {
 a = aa;
 }

 public int getA()
{
return a;
}
 }
 


 Now, when i call x.setA(123) from webapp1, an instance of x.java will be
 loaded (obviously, since this is the first time), and the method be
 called
 appropriately. Now, if I now call x,getA() from webapp2, I expect to get
 the value 123. But I don't .. :-(  Instead I get a null as returned
 value.


 Moreover, I also see that static initializer is called both times !

 Any ideas as to why ??? (I use Tomcat 5.5.26).


 Looking forward to replies.
 Ajay Garg




 --
 View this message in context:
 http://www.nabble.com/Doubt-on-lifecycle-of-a-class-in-%22shared%22-folder-tp18502300p18502310.html
 Sent from the Tomcat - User mailing list archive at Nabble.com.


 -
 To start a new topic, e-mail: users@tomcat.apache.org
 To unsubscribe, e-mail: [EMAIL PROTECTED]
 For additional commands, e-mail: [EMAIL PROTECTED]


 
 -
 To start a new topic, e-mail: users@tomcat.apache.org
 To unsubscribe, e-mail: [EMAIL PROTECTED]
 For additional commands, e-mail: [EMAIL PROTECTED]
 
 
 

-- 
View this message in context: 
http://www.nabble.com/Doubt-on-lifecycle-of-a-class-in-%22shared%22-folder-tp18502300p18504589.html
Sent from the Tomcat - User mailing list archive at Nabble.com.


-
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: Doubt on lifecycle of a class in shared folder

2008-07-17 Thread java_is_everything

Shared Class :

///
package client;

import java.util.ArrayList;

public class Sharer
{
public static ArrayList listForOthers  = null;  

static
{
System.out.println(STATIC ON WORK );  
}

public static ArrayList getListForOthers()
  {
  if(listForOthers != null)
  {
  System.out.println(Returned is NOT NULL.);
  }
  else
  {
  System.out.println(Returned is NULL);
  }
  return listForOthers;
  }
  
  public static void setListForOthers(ArrayList list)
  {
  listForOthers = new ArrayList();
  
  for(int i = 0; i  list.size(); i++)
  {   
  ClientSideEvent ce = new ClientSideEvent();
  ClientSideEvent ce2 = (ClientSideEvent) list.get(i);
  ce.setTimestamp(ce2.getTimestamp());
  ce.setId(ce2.getId());
  ce.setType(ce2.getType());
  ce.setDescription(ce2.getDescription());
  listForOthers.add(ce);
  } 
  
  }
}
//





webapp2 :


package client;

import java.util.ArrayList;

import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.RootPanel;


/**
 * Entry point classes define codeonModuleLoad()/code.
 */
public class AnotherWelcomePage implements EntryPoint {

  /**
   * This is the entry point method.
   */
  public void onModuleLoad() {
  final Button button = new Button(Doosra Search);
  
  RootPanel.get(slot2).add(button); 
  
  ArrayList list = Sharer.getListForOthers();
  if(list != null)
  {
  button.setText(Returning OK with  + list.size());
  }
  else
  {
  button.setText(Problem !!);
  }
   }
}
///




webapp1 :


package client;

import java.util.ArrayList;

import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.ClickListener;
import com.google.gwt.user.client.ui.RootPanel;
import com.google.gwt.user.client.ui.Widget;

//import com.google.gwt.user.client.ui.;

/**
 * Entry point classes define codeonModuleLoad()/code.
 */
public class EntryPointClass implements EntryPoint {

  /**
   * This is the entry point method.
   */
  public void onModuleLoad() {

  ArrayList list = new ArrayList();
  ClientSideEvent event = new ClientSideEvent();
  
  final Button b = new Button(Initial Display);
  b.addClickListener(new ClickListener()
  {

public void onClick(Widget sender) 
{

ArrayList nowlist = Sharer.getListForOthers();
if(nowlist == null)
{
b.setText(Null returned);
}   
else
{
b.setText(Size is  + 
Integer.toString(nowlist.size()));
}

}   
  });
  
  RootPanel.get(slot1).add(b);  
  event.setTimestamp( time is money ); // It's ok, needs a string
  event.setId(222);
  event.setType(type);
  event.setDescription(description);
  list.add(event);
  Sharer.setListForOthers(list);
  

  //button.setText(Integer.toString(list.size()));
  }
}
/



Now, webapp1 sets the list size to 1. Now when Sharer.getListForOthers()
from webapp1, Size is 1, while when Sharer.getListForOthers() from
webapp2, it shows Problem !!.

Any light ?/



Ajay Garg

Mikolaj Rydzewski-2 wrote:
 
 java_is_everything wrote:
 public int getA()
{
return a; 
}
   
 [...]
 value 123. But I don't