java卡中小程序的坚固性

bfhwhh0e  于 2021-07-13  发布在  Java
关注(0)|答案(1)|浏览(299)

我用java卡开发了一个小程序,效果很好。现在我正在研究这个applet的坚固性,更确切地说,如果在applet执行过程中卡被取出会发生什么。
我想知道是否有例外处理这种事情?
我在寻找这样的东西:

try {
...
}
// If the card is disconnected while the applet execution
catch (Exception e) {
...
}

先谢谢你。

nwnhqdif

nwnhqdif1#

因为智能卡里面没有电池,所以你不能有电池 try ... catch ... 这样地。或者你可以利用 Transactions . 事务api只是为您的目标而提供的。介于 beginTransation() 以及 commitTransation() 方法,仅当 commitTransation() 成功完成。如果之前有任何例外/卡撕裂或卡重置发生 commitTransation() ,一切都会回到原来的状态(即回到以前的状态) beginTransaction() )
它是这样的:

.
    .
    JCSystem.beginTransaction();
    //put your critical code here.
    JCSystem.commitTransaction();
    .
    .

你也可以使用 JCSystem.commitTransaction(); 在以下特定情况下终止交易:

.
    .
    JCSystem.beginTransaction();

    //put your critical code here.
    if (condition) {
    JCSystem.commitTransaction();
    }

    JCSystem.commitTransaction();
    .
    .

请注意:
交易卡的缓冲区有限。所以你不能把整个程序放在一个事务中。但对于典型的关键方法,它有足够的缓冲区大小。
不能使用嵌套事务。

相关问题