Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
1回呼び出し可能で、2分間のような期間中、2分間隔でそれ以上呼び出されないようにブロックされるメソッドを作成するための優れた効率的な方法は何ですか. 2 分間が経過した後にのみ、再度呼び出すことができます。
何か案は?
System.currentTimeMillis()a を静的変数として保持および更新し、 currentSystem.currentTimeMillis()が stored より 2 分大きいかどうかを確認できSystem.currentTimeMillis()ます。もしそうなら; そうでない場合は、やりたいことを何でもしてください。単純に返すか、例外をスローして後でキャッチすることができます。それはあなたの呼び出しです。
System.currentTimeMillis()