• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Calling Threads from servlet

 
Ranch Hand
Posts: 61
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Iam not sure what will be the effect of doing the foll:
Servlet spawns off a thread and passes on parameters a2,b2,c2. Inside this thread I have member variables.
public class A extends Thread
String a;
String b;
String c;
{
public A(a1,b1,c1)
{
this.a = a1;
this.b = b1;
this.c = c1;
}
}
Is this thread safe? Iam confused.
Generally, by declaring member variables, each instance has its own copy and dont share it isnt? What about the above scenario?
 
Ranch Hand
Posts: 1365
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
A field can't simply be thread safe, although since String is immutable in the example you give there almost definately wouldn't be any thread safety issues so long as the fields are only accessed from within a single running thread. If you start the thread multiple times or access the fields from another thread, though, all bets are off.
 
reply
    Bookmark Topic Watch Topic
  • New Topic