Issue when executing asynchronous tasks using ExecutorService

后端 未结 1 791
长发绾君心
长发绾君心 2021-01-27 15:34

I had asked a question earlier regarding ExecutorService and Apache Velocity initialization. To give a quick recap -- I have a Java EE frontend which accepts user requests and

1条回答
  •  终归单人心
    2021-01-27 16:21

    your code is not thread-safe since you are sharing config and template across all thread instances (and continuously re-setting them). the easiest way to make it thread safe would be to make config and template local variables in the method instead of static members. as @JBNizet pointed out in the comments, you have a similar problem in mailBuilder with a and b. you might want to first check out some tutorials on object oriented programming fundamentals and then circle back to this issue (hint, in general you should avoid static member variables except for constants).

    0 讨论(0)
提交回复
热议问题