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 Caldarale, Charles R
> From: Edward Song [mailto:[EMAIL PROTECTED]
> Subject: RE: Doubt on lifecycle of a class in "shared" folder
>
> I believe it is because you are sharing the class definition,
> not instances, even if they are static instances.
>
> So webapp1 will create a static instance of Sharer, so will
> webapp2 off of the same class definition, but each will have
> its own instance.

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]



RE: Doubt on lifecycle of a class in "shared" folder

2008-07-17 Thread Edward Song
I believe it is because you are sharing the class definition, not instances,
even if they are static instances.

So webapp1 will create a static instance of Sharer, so will webapp2 off of
the same class definition, but each will have its own instance.


-Original Message-
From: java_is_everything [mailto:[EMAIL PROTECTED] 
Sent: Thursday, July 17, 2008 6:39 AM
To: users@tomcat.apache.org
Subject: Re: Doubt on lifecycle of a class in "shared" folder


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 onModuleLoad().
 */
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 onModuleLoad().
 */
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

Re: Doubt on lifecycle of a class in "shared" folder

2008-07-17 Thread Mikolaj Rydzewski

java_is_everything wrote:

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 ?/
  

Maybe gwt adds some magick?

I have checked it now on 5.x and 6.x - works as designed.

--
Mikolaj Rydzewski <[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]



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 onModuleLoad().
 */
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 onModuleLoad().
 */
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; 
>>}
>>   
> [...]

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 Konstantin Kolinko
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]



Re: Doubt on lifecycle of a class in "shared" folder

2008-07-17 Thread Mikolaj Rydzewski

java_is_everything wrote:

public int getA()
   {
   return a; 
   }
  

[...]

value 123. But I don't .. :-(  Instead I get a null as returned value.
  

It's impossible to return null from such method.

Show us complete code (both shared class and webapps).

--
Mikolaj Rydzewski <[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]



Re: Doubt on lifecycle of a class in "shared" folder

2008-07-16 Thread java_is_everything

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]



Doubt on lifecycle of a class in "shared" folder

2008-07-16 Thread java_is_everything

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-tp18502300p18502300.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]