bcr666
bcr666

Reputation: 2197

Why is my thread blocking on call to service method

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?

Upvotes: 0

Views: 243

Answers (1)

ruakh
ruakh

Reputation: 183251

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.

Upvotes: 2

Related Questions