Java – what does it mean when someone says “the result is not thread safe”
When I read this document, I was writing an application specific Java HBase API wrapper:
http://hbase.apache.org/apidocs/org/apache/hadoop/hbase/client/Result.html
It says this class is not a threat to security * *
What does it really mean? It's not thread safe I'm basically a C programmer. If someone says that the function strtok () is not thread safe, I won't use it in a multithreaded environment It's not a good idea for things like strtok () to use static variables and call this function through two different threads
Is Java the same?
I have one function:
public String get(String key,String family) { Get get = new Get(key.getBytes()); get.addFamily(family.getBytes()); Result result = null; try { result = _table.get(get); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } return ""; }
The get function may be called by multiple threads Will it be used in some way with unsafe results?
Solution
This means that if a given class object is accessed through various threads, calling its methods in these threads may lead to unpredictable results, because there is no interaction between threads. The basic reason for this unpredictable result is that the same data of objects is shared among various threads You can view more information about thread safety here in Wikipedia article
After completing the code, I found that you are at line result =_ table. Member variables are used in get (get)_ table; . So, most likely, it's not thread safe