[ https://issues.apache.org/jira/browse/HIVE-1647?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12916676#action_12916676 ]
He Yongqiang commented on HIVE-1647: ------------------------------------ +1 running tests > Incorrect initialization of thread local variable inside IOContext ( > implementation is not threadsafe ) > -------------------------------------------------------------------------------------------------------- > > Key: HIVE-1647 > URL: https://issues.apache.org/jira/browse/HIVE-1647 > Project: Hadoop Hive > Issue Type: Bug > Components: Server Infrastructure > Affects Versions: 0.6.0, 0.7.0 > Reporter: Raman Grover > Assignee: Liyin Tang > Fix For: 0.7.0 > > Attachments: HIVE-1647.patch > > Original Estimate: 0.17h > Remaining Estimate: 0.17h > > Bug in org.apache.hadoop.hive.ql.io.IOContext > in relation to initialization of thread local variable. > > public class IOContext { > > private static ThreadLocal<IOContext> threadLocal = new > ThreadLocal<IOContext>(){ }; > > static { > if (threadLocal.get() == null) { > threadLocal.set(new IOContext()); > } > } > > In a multi-threaded environment, the thread that gets to load the class first > for the JVM (assuming threads share the classloader), > gets to initialize itself correctly by executing the code in the static > block. Once the class is loaded, > any subsequent threads would have their respective threadlocal variable as > null. Since IOContext > is set during initialization of HiveRecordReader, In a scenario where > multiple threads get to acquire > an instance of HiveRecordReader, it would result in a NPE for all but the > first thread that gets to load the class in the VM. > > Is the above scenario of multiple threads initializing HiveRecordReader a > typical one ? or we could just provide the following fix... > > private static ThreadLocal<IOContext> threadLocal = new > ThreadLocal<IOContext>(){ > protected synchronized IOContext initialValue() { > return new IOContext(); > } > }; -- This message is automatically generated by JIRA. - You can reply to this email to add a comment to the issue online.