Listing 1

public void bulkLoadData(DataBatch batch) {
	int batchId = batch.getId();

	// Since this executeUpdate call doesnŐt happen in a separate
	// transaction, it wouldn't be visible anyway, but the effect is
	// far worse: a cross-resource deadlock.
	executeUpdate("update batch_status set status='Started' " +
		"where batch_id=" + batchId);
	validateData(batch);
	updateBatchStatus(batchId, "Validated"); // RequiresNew EJB call
	loadDataStage1(batch);
	updateBatchStatus(batchId, "Stage 1 complete"); // RequiresNew EJB call
	loadDataStage2(batch);
	updateBatchStatus(batchId, "Stage 2 complete"); // RequiresNew EJB call
	finalizeDataLoad(batch);
	updateBatchStatus(batchId, "Complete"); // RequiresNew EJB call
}


Listing 2

public class SimpleCache {
	private Map cache = new HashMap();

	public synchronized Object get(String key) {
		if (cache.containsKey(key)) {
			return cache.get(key);
		} else {
			Object value = queryForValue(key);
			cache.put(key, value);
			return value;
		}
	}

	private Object queryForValue(String key) {
		return executeQuery("select value from cache_table " +
			"where key='" + key + "'");
	}

	public synchronized void clearCache() {
		cache.clear();
	}

	// other methods omitted for brevity
}