I am having a code like below in my class that will act like my 'Task' class. i will create multiple instances of this class and pass it to the threadpool
class Task {
public void doJob() {
String s = informationDto.getName();
}
}
DTO:
class InformationDto{
private String name;
public getName(){}
public setName(String n){}
}
i am wondering about the informationDto.getName();
statement. will it be return me the correct name always in a multithreaded environment?
what happens if the getName()
method is static?
i want to use informationDto
each for every Task
class i am creating. what will be the best way to do this?
1) i want to keep one InformationDto
for each Task
class.
2) since instance variables are not thread safe i am wondering if i access getName()
method (since name
is a instance variable ) would i get the correct name that i set in the Task
class?
3) it is like if i use a util class inside the Task
class will it be thread safe? if not how can i use kind of util instance in a thread safe manner?