• Post Reply Bookmark Topic Watch Topic
  • New Topic

Calling Threads from servlet

 
Priya Venkatesan
Ranch Hand
Posts: 61
  • Mark post as helpful
  • send pies
  • 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?
 
David Weitzman
Ranch Hand
Posts: 1365
  • Mark post as helpful
  • send pies
  • 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.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!