0

My Thread and service classes:

public class InterfaceThread implements Runnable {

    private static final Logger logger = Logger.getLogger(InterfaceThread.class);

    @Autowired
    private ScanService scanService;
    
    @Override
    public void run() {
        String accessToken = getAccessTokenFromJSON(getResponse(null, URL_UPDATE_ACCESS_TOKEN, METHOD_POST).getText());
        logger.debugv("Access Token Found {0}", accessToken);
        
        String pendingOrdersJson = getResponse(accessToken, URL_PENDING_ORDERS, METHOD_GET).getText();
        logger.infov("Pending Orders {0}", pendingOrdersJson);

        String singleOrderJson = getResponse(accessToken, String.format(URL_SINGLE_ORDER, "3353246000022471593"), METHOD_GET).getText();
        logger.infov("Single Order {0}", singleOrderJson);
        
        doProcess(accessToken);
    }
    
    private void doProcess(String accessToken) {
        // read tblScan for any records that have an order number and serial number that are not completed sent and not 5 tries
        // loop through serialNumbers and find a detail record and update it

        System.out.println("getting List");
        List<Scan> scans = scanService.listReadyForTransmission();
        System.out.println(Arrays.toString(scans.toArray()));
        for (Scan scan : scans) {
            processScan(accessToken, scan);
        }
    }
}
    
@Service
public class ScanServiceImpl implements ScanService {

    @Autowired 
    ScanDao scanDao;
    
    @Override
    @Transactional
    public List<Scan> listReadyForTransmission() {
        System.out.println("Calling the dao for list");
        return scanDao.listReadyForTransmission();
    }
}

My logs:

14:42:08 INFO [pool-5-thread-1]:web.InterfaceThread.run()72 - Pending Orders {Returned JSON}
14:42:09 INFO [pool-5-thread-1]:web.InterfaceThread.run()75 - Single Order {Returned JSON}
getting List

So you can see from the logs that the Pending Orders works and the Single Order work, then it gets to "getting list", which should immediately be followed by "Calling the dao for list", but instead the thread is blocking. Why is that, and how do I stop it?

Janez Kuhar
  • 3,705
  • 4
  • 22
  • 45
bcr666
  • 2,157
  • 1
  • 12
  • 23

1 Answers1

2

Most likely you're getting stuck in whatever interceptor is handling the @Transactional annotation.

To debug this, I recommend using the jstack utility, which ships with the JDK (in the same directory as java); it will dump the stacktraces of all running threads, so you can see where this thread is hanging.

ruakh
  • 175,680
  • 26
  • 273
  • 307
  • Well, I tried that jstack, but couldn't find my thread. Also I was unable to make heads or tails out of the dump. Your comment lead me to search for "java thread call @Transactional" though and I found this https://stackoverflow.com/questions/11275471/calling-transactional-methods-from-another-thread-runnable. I changed my thread calling (ScheduledExecutorService) to match the OP's (TaskScheduler) and followed main answer and it works. – bcr666 Aug 13 '21 at 18:03