Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Thread with Static method  RSS feed

 
jacob deiter
Ranch Hand
Posts: 585
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Class A{

int a=1;
int a=2;
int a=3;
int a=4;
int a=5;
int a=6;
int a=7;
int a=8;
}

Consider Thread -1 ,accessing the class A, for EX: at line int i=7;

1)Meanwhile another thread trying to access the class A, after the Thread 1 finished its execution, Thread 2 starts it execution ?
2)if Yes ,then in Effective java book ,suggested that use static method if it is common for all instance. In this case ,in multi thread environment ,one thread collapse each others? Because it is static

please correct if I am wrong
 
Henry Wong
author
Sheriff
Posts: 22841
119
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Class A{

int a=1;
int a=2;
int a=3;
int a=4;
int a=5;
int a=6;
int a=7;
int a=8;
}

Consider Thread -1 ,accessing the class A, for EX: at line int i=7;


This is not valid Java code. And what do you mean by accessing class A? Do you mean using one of the instance variables?

1) Meanwhile another thread trying to access the class A, after the Thread 1 finished its execution, Thread 2 starts it execution ?


What is the question here?

2) if Yes ,then in Effective java book ,suggested that use static method if it is common for all instance. In this case ,in multi thread environment ,one thread collapse each others? Because it is static


There are no static methods in this example. Heck, there are no methods of any kind in this example.

Please elaborate on the questions....

Henry
 
Peter Lawrey
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Henry Wong:


There are no static methods in this example. Heck, there are no methods of any kind in this example.

There is also nothing static, nor is there a line "int i=7;"

I would suggest learning basic java before worrying about Threads.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!