如何将用户数据传递给线程?

时间:2022-10-28 17:34:00

I am not sure I am on the right track or not. In my application jdbc connection is created and some process calls commit over that transaction. In the same flow, a thread is created and again call the same process to perform commit. But the later commit is not committing correct user data in WHO columns. WHO columns need to take its values from user session. I have checked that if i dont create thread and directly call the process then WHO columns are updating correctly. On thread creation, issue arising. Application is created using adf model. plz suggest how to pass user context to thread.

我不确定我是否走在正确的轨道上。在我的应用程序中,创建了jdbc连接,并且某些进程调用通过该事务进行提交。在同一个流程中,创建一个线程并再次调用相同的进程来执行提交。但后来的提交并未在WHO列中提交正确的用户数据。 WHO专栏需要从用户会话中获取其值。我已经检查过,如果我不创建线程并直接调用该过程,那么WHO列正在正确更新。在线程创建,问题出现。应用程序是使用adf模型创建的。 plz建议如何将用户上下文传递给线程。

3 个解决方案

#1


2  

Unless you post the code, it's hard to answer your questions. But based on you wordings, I think you are having difficulty passing some variable/data to threads. The easiest and most simple way is to use constructors. When you are creating an object to call the class implementing/extending the thread class, pass the data as parameters. Then use a constructor in the called class to get the values and use them as needed. I hope that helps and was in accordance to the question you asked.

除非您发布代码,否则很难回答您的问题。但根据你的措辞,我认为你很难将一些变量/数据传递给线程。最简单和最简单的方法是使用构造函数。在创建对象以调用实现/扩展线程类的类时,将数据作为参数传递。然后在被调用的类中使用构造函数来获取值并根据需要使用它们。我希望这有助于并且符合您提出的问题。

#2


0  

you can pass the data to thread using a class with getter and setter method, set all the data by creating object before starting thread and using getter method you can get it in the thread..!

你可以使用带有getter和setter方法的类将数据传递给线程,通过在启动线程之前创建对象来设置所有数据,并使用getter方法,你可以在线程中获取它。

 public Class  NormalClass
{ 
     int data = 0;
     public void setData(int a)
   {
       this.a = a;
    }
    public int getData(int a)
   {
     return this.a;
   }    
}

Before starting thread set data in class, then in run method you can access it

在类中启动线程集数据之前,在run方法中可以访问它

#3


0  

You can use ThreadLocal to maintain some context related to the current thread, You can get more information on Usage of ThreadLoacal

您可以使用ThreadLocal维护与当前线程相关的某些上下文,您可以获得有关ThreadLoacal的使用的更多信息

#1


2  

Unless you post the code, it's hard to answer your questions. But based on you wordings, I think you are having difficulty passing some variable/data to threads. The easiest and most simple way is to use constructors. When you are creating an object to call the class implementing/extending the thread class, pass the data as parameters. Then use a constructor in the called class to get the values and use them as needed. I hope that helps and was in accordance to the question you asked.

除非您发布代码,否则很难回答您的问题。但根据你的措辞,我认为你很难将一些变量/数据传递给线程。最简单和最简单的方法是使用构造函数。在创建对象以调用实现/扩展线程类的类时,将数据作为参数传递。然后在被调用的类中使用构造函数来获取值并根据需要使用它们。我希望这有助于并且符合您提出的问题。

#2


0  

you can pass the data to thread using a class with getter and setter method, set all the data by creating object before starting thread and using getter method you can get it in the thread..!

你可以使用带有getter和setter方法的类将数据传递给线程,通过在启动线程之前创建对象来设置所有数据,并使用getter方法,你可以在线程中获取它。

 public Class  NormalClass
{ 
     int data = 0;
     public void setData(int a)
   {
       this.a = a;
    }
    public int getData(int a)
   {
     return this.a;
   }    
}

Before starting thread set data in class, then in run method you can access it

在类中启动线程集数据之前,在run方法中可以访问它

#3


0  

You can use ThreadLocal to maintain some context related to the current thread, You can get more information on Usage of ThreadLoacal

您可以使用ThreadLocal维护与当前线程相关的某些上下文,您可以获得有关ThreadLoacal的使用的更多信息