给出从会话bean调用两个Web服务方法的示例,如果在对两个方法的调用之间抛出异常,该怎么办?在不调用Web服务的情况下,事务将回滚并且不会造成任何损害.但是,Web服务不会回滚.当然,即使使用单一的Web服务也存在问题.虽然这是一个通用问题,但我对与EJB会话bean有关的解决方案感兴趣.
一个简单而定制的答案是为Web服务为每个"真实功能"方法添加一个特殊的"回滚方法".我要求的是一些标准化的方法.
好的,这是代码,然后讨论如下:
public class FlatArrayList {
private static ArrayList<TestWrapperObject> probModel = new ArrayList<TestWrapperObject>();
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
int [] currentRow = new int[10];
int counter = 0;
while (true) {
for (int i = 0; i < 10; i++) {
currentRow[i] = probModel.size();
}
TestWrapperObject currentWO = new TestWrapperObject(currentRow);
probModel.add(counter, currentWO);
TestWrapperObject testWO = probModel.get(counter);
// System.out.println(testWO);
counter++;
if (probModel.size() == 10) break;
}
// Output the whole ArrayList …
Run Code Online (Sandbox Code Playgroud)