简体   繁体   English

Java Card中小程序的坚固性

[英]Sturdiness of an applet in Java Card

I developed an applet in Java Card and it works fine. 我用Java Card开发了一个applet,它运行良好。 Now I am working on the sturdiness of this applet and more precisely, what happens if the card is deplugged during the applet execution for example. 现在,我正在研究此applet的坚固性,更确切地说,是例如在applet执行期间拔掉卡会发生什么情况。

I am wondering if there is an Exception which handle this kind of things ? 我想知道是否存在处理此类事情的异常?

I am searching for something like : 我正在寻找类似的东西:

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

Thank you in advance. 先感谢您。

As the smart cards haven't any battery inside, you can't have any try ... catch ... like this. 由于智能卡内部没有电池,因此您无法try ... catch ...像这样。 Alternatively you can take advantages of Transactions . 或者,您可以利用Transactions优势。 The Transaction APIs are provided just for your goal. 仅为您的目标提供了交易API。 The operations that are between beginTransation() and commitTransation() methods, apply only if the commitTransation() complete successfully. beginTransation()commitTransation()方法之间的操作仅在commitTransation()成功完成时才适用。 And if any exeption/card tear or card reset happens before commitTransation() , everything returns to its original state (ie to the state that it has before beginTransaction() ) 而且,如果在commitTransation()之前发生了任何意外/卡撕裂或卡重置的情况,则一切都将返回其原始状态(即,返回到beginTransaction()之前的状态)

It is like this : 就像这样:

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

You can also use JCSystem.commitTransaction(); 您也可以使用JCSystem.commitTransaction(); to terminate a transaction in a specific situation as follow : 在特定情况下终止交易如下:

    .
    .
    JCSystem.beginTransaction();

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

    JCSystem.commitTransaction();
    .
    .

Note that: 注意:

  1. Transactions have a limited buffer in cards. 交易卡中的缓冲区有限。 So you can't put whole the program inside a transaction. 因此,您不能将整个程序放在一个事务中。 But for typical critical methods, it has enough buffer size. 但是对于典型的关键方法,它具有足够的缓冲区大小。
  2. You can't use nested Transactions. 您不能使用嵌套事务。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM