title: Concurrency issues in java accessing Jdbc Impala
body: <p>What I want to do: Have two thread t1,t2 where t1 connecting to I1 impala cluster and t2 connecting  to I2</p>
  <p>Both t1 and t2 has the task of executing set of queries in the respective databases.</p>
  <p>Below is the pseudo code:</p>
  <pre><code>    queriesMap(queryName,query)//got the queries dynamically from another table, customized and set to map here
  
      myThreadMethod(queriesMap, connUrl)
     {
     conn = getImpalaConnection(connUrl)
     stmt = conn.createStatement()
     for each query in queriesMap
     {
         ResultSet rs=stmt.executeQuery(query);
         ResultSetMetadata rsMetadata = rs.getMetadata();
         rs.next(); //assuming retrieving only the sum- only one row
         for(i=1;i&lt;=rsMetadata .getColumnCount();i++)
        {
            //append column names and print
            //append result values and print
        }
      }
      }
  </code></pre>
  <p>Now the column and result values that are being printed are not the same way every time. if the same code is run without threads, the results are as expected.
  Note: I have tried threadlocal but it didn't help</p>
  <p>Could anyone please let me know what could be causing issue here?</p>
  <p>Expected Result:<br />
  Thread1</p>
  <pre><code> Query1   q1-C1 q1-C2 q1-C3 q1-c4 q1-c5
            q1-V1 q1-V2 q1-V3 q1-V3 q1-V5
  
   Query2  q2-C1 q2-C2 q2-C3 
           q2-V1 q2-V2 q2-V3 
  
   Query3  q3-C1 q3-C2 q3-C3 q3-c4 q3-c5
           q3-V1 q3-V2 q3-V3 q3-V3 q3-V5
  </code></pre>
  <p>Thread2</p>
  <pre><code> Query1   q1-C1 q1-C2 q1-C3 q1-c4 q1-c5
            q1-V1 q1-V2 q1-V3 q1-V3 q1-V5
  
   Query2  q2-C1 q2-C2 q2-C3 
           q2-V1 q2-V2 q2-V3 
  
   Query3  q3-C1 q3-C2 q3-C3 q3-c4 q3-c5
           q3-V1 q3-V2 q3-V3 q3-V3 q3-V5
  </code></pre>
  <p>Result I am currently getting and this is not always the same, only for an example:  q1-c1 column1 of query 1 , q1-v1 value/result 1 of query 1</p>
  <p>Thread1:</p>
  <pre><code> Query1   q1-C1 q1-C2 q1-C3 q1-c4 q1-c5
            q1-V1 q1-V2 q1-V3 q1-V3 q1-V5
  
   Query2  q2-C1 q2-C2 q2-C3 
           q2-V1 q2-V2 q2-V3 
  
   Query3  q3-C1 q3-C2 q3-C3 q3-c4 q3-c5
           q3-V1 q3-V2 q3-V3 q3-V3 q3-V5
  </code></pre>
  <p>T2:</p>
  <pre><code> Query1  q1-C1 q1-C2 q1-C3 q1-c4 q1-c5
           q1-V1 q1-V2 q1-V3 q1-V3 q1-V5
  
   Query2  q2-C1 q2-C2 q2-C3 
           q2-V1 q2-V2 q2-V3 
  
   **Query3  q2-C1 q2-C2 q2-C3 
           q3-V1 q3-V2 q3-V3** 
  </code></pre>
  <p>As shown from expected and current results, issue is with thread2 Query3 there is jumbling of column metadata. This result is not consistent, there is issue once with Query1, once with Query2 etc</p>