getting TransportContext null in WorkManagerTaskExecutor

477 Views Asked by At

Am trying to get the TransportContext

(from TransportContextHolder.getTransportContext();)

Which am able to get the context, connection and HttpServletRequest in normal flow.

But I have a scenario, where am creating a parallel call using Spring WorkManagerTaskExecutor). In the new thread am trying to get the Spring TransportContext, which it is returning null.

Can someone help how to get the TransportContext in concept of WorkManagerTaskExecutor.

1

There are 1 best solutions below

0
On

You cant pass Transport context into task that you execute by WorkManagerTaskExecutor.

executor.execute(new Task(TransportContextHolder.getTransportContext()){
   //here constructor and property to store context
});

But it is not a good approach. Data received from transport context in another thread can be invalid, and you should not make any sending operations. If you need transport information while task execution just read it in original thread and pass to task as described above. Sending data from another thread could not work correct.