struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Ashish Kulkarni <kulkarni_ash1...@yahoo.com>
Subject RE: [OT] basic java question
Date Wed, 12 Mar 2003 14:38:37 GMT
Hi,

The static methods in my class will be accessed from
servlet, and since servlet will have multiple instance
accessing these classes it is a case of multi
threading 
does anyone have a example code for writing this kind
of code
Ashish
--- Mark Galbreath <mark_galbreath@qat.com> wrote:
> Rewrite the classes using the factory design pattern
> and get their
> respective instances in other classes using static 
> initializers.  Whether
> or not you need to synchronize the methods is
> answered by the question: If
> two threads gain concurrency of the object will the
> resultant change in
> state corrupt the integrity of the output?
> 
> cf., Joshua Block, "Effective Java"
> (Sun/Addison-Wesley 2001): 5-9 (has a
> great forward by Guy Steele, too).
> 
> Mark
> 
> -----Original Message-----
> From: Ashish Kulkarni
> [mailto:kulkarni_ash1312@yahoo.com] 
> Sent: Tuesday, March 11, 2003 4:36 PM
> 
> Hi Jeff,
> This tutorial talks about threads and when to make
> them synchronize, but my problem is about a kind of
> utility class or worker class which has 2 methods
> which i want to keep static so i dont have to create
> instance of that class to use these methods..
> and i my question is i would not make them
> synchronized, if they are independent and do not use
> any other class resources, and make them
> synchronized
> if i have some class variable which is accessed bye
> them, so no 2 instance of classes can use the method
> at a time( this is off course going to affect
> performace) 
> but i my doubt is, if one static method is calling
> other static method in same class, should i make
> them synchronized???
> 
> Ashish
> --- Jeff Kyser <ktrails@comcast.net> wrote:
> > Ashish,
> > 
> > Check out the following trail on threads at
> > java.sun.com,
> > 
> > 
> >
>
http://java.sun.com/docs/books/tutorial/essential/threads/index.html
> > 
> > it discusses synchronization and when you need to
> > use it.
> > 
> > -jeff
> > 
> > On Tuesday, March 11, 2003, at 02:41  PM, Ashish
> > Kulkarni wrote:
> > 
> > > Hi,
> > >
> > > I have a following class with 2 static methods,
> > should
> > > i make the methods synchronized??
> > > I would not make then synchronized, if those
> where independent,
> > > but i am not sure since one method is calling
> > other to
> > > get some data
> > > I will call this method from any class
> > > String a = MyClass.getOtherThing("123");
> > > or
> > > String b = MyClass.getSomeThing("567");
> > > (this is just a example code)
> > >
> > > public class MyClass
> > >  {
> > >    public static String getSomeThing(String abc)
> > >   {
> > >    // some logic
> > >     return "1";
> > >   }
> > >
> > >    public static String getOtherThing(String
> abc)
> > >   {
> > >     // calling method getSomeThing here
> > >       String s = getSomeThing(abc);
> > >      // do some logic and return result
> > >      return "2";
> > >   }
> > >  }
> > >
> > >
> > >
> __________________________________________________
> > > Do you Yahoo!?
> > > Yahoo! Web Hosting - establish your business
> > online
> > > http://webhosting.yahoo.com
> > >
> > >
> >
>
---------------------------------------------------------------------
> > > To unsubscribe, e-mail:
> > struts-user-unsubscribe@jakarta.apache.org
> > > For additional commands, e-mail:
> > struts-user-help@jakarta.apache.org
> > >
> > 
> > 
> >
>
---------------------------------------------------------------------
> > To unsubscribe, e-mail:
> struts-user-unsubscribe@jakarta.apache.org
> > For additional commands, e-mail:
> > struts-user-help@jakarta.apache.org
> > 
> 
> 
> __________________________________________________
> Do you Yahoo!?
> Yahoo! Web Hosting - establish your business online
> http://webhosting.yahoo.com
> 
>
---------------------------------------------------------------------
> To unsubscribe, e-mail:
> struts-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail:
> struts-user-help@jakarta.apache.org
> 
> 
> 
>
---------------------------------------------------------------------
> To unsubscribe, e-mail:
> struts-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail:
> struts-user-help@jakarta.apache.org
> 


__________________________________________________
Do you Yahoo!?
Yahoo! Web Hosting - establish your business online
http://webhosting.yahoo.com

---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org


Mime
View raw message