How to cancel an already scheduled TimerTask?

I have a tiny problem that I can't seem to do right. I have the following class in java: package pooledtcpconnector.utilities; import java.io.IOException; import java.io.InputStream; import java.util.Timer; import java.util.TimerTask; import java.util.logging.Level; import java.util.logging.Logger; public final class Notifier implements Runnable { private final ILogger logger; p

如何取消已安排的TimerTask?

我有一个小问题,我似乎无法做正确的事情。 我在java中有以下类: package pooledtcpconnector.utilities; import java.io.IOException; import java.io.InputStream; import java.util.Timer; import java.util.TimerTask; import java.util.logging.Level; import java.util.logging.Logger; public final class Notifier implements Runnable { private final ILogger logger; private Timer mTimer; privat

java.util.TimerTask cancel() method exact semantics

I am lost a bit with TimerTask cancel() method semantics comparing JavaDoc with real behaviour and source code. JavaDoc says about return value: Returns false if the task was scheduled for one-time execution and has already run, or if the task was never scheduled, or if the task was already cancelled. However, looking into the code it looks like false maybe returned if a task has not alread

java.util.TimerTask cancel()方法的确切语义

我用TimerTask的cancel()方法语义丢失了一点,它比较了JavaDoc与真实行为和源代码。 JavaDoc说关于返回值: 如果任务计划为一次执行并且已经运行,或者如果任务从未计划,或者任务已被取消,则返回false。 但是,查看代码时,如果任务尚未运行,则可能返回false,但会运行。 我正在查看java.util.Timer代码(mainLoop()方法): TimerTask task; boolean taskFired; synchronized(queue) { // Wait for queue to

Cancel a scheduled fixed rate task depending on the result of the task

I'm using Spring's TaskScheduler to schedule a periodic task. ScheduledFuture scheduleAtFixedRate(Runnable task, long period); I understand that I can call cancel() on the ScheduledFuture to stop the recurring task from being executed. But I'd like to cancel the recurring scheduled task depending on the result of the execution of the task, and am not sure how to best do that. Doe

根据任务的结果取消预定的固定费率任务

我使用Spring的TaskScheduler来安排定期任务。 ScheduledFuture scheduleAtFixedRate(Runnable task, long period); 我知道我可以调用ScheduledFuture上的cancel()来停止执行循环任务。 但是我想取消定期执行的任务,具体取决于任务的执行结果,我不知道如何做到最好。 ScheduledFuture是否允许我访问每个执行任务的结果? 或者,我是否需要某种可以保留对此ScheduledFuture的引用的任务侦听器,并以这种方式取消它?

How to stop the task scheduled in Java.util.Timer class

I am using java.util.timer class and I am using its schedule method to perform some task, but after executing it for 6 times I have to stop its task. How should I do that? Keep a reference to the timer somewhere, and use: timer.cancel(); timer.purge(); to stop whatever it's doing. You could put this code inside the task you're performing with a static int to count the number of tim

如何停止在Java.util.Timer类中计划的任务

我正在使用java.util.timer类,我使用它的调度方法来执行一些任务,但执行它6次后,我不得不停止它的任务。 我应该怎么做? 在某处保留对定时器的引用,并使用: timer.cancel(); timer.purge(); 停止它正在做的事情。 你可以把这段代码放到你正在执行的任务中,用一个static int来计算你已经过去的次数,例如 private static int count = 0; public static void run() { count++; if (count >= 6) {

Calculate cell sizes and draw (with lines in between) them

I want to draw a grid and draw stuff in the cells (to keep things easy just fill them). Overall I've got it pretty much working only in some panel sizes the cell is about 1 pixel off of where it should be placed (overlapping the line). TBH I haven't really done enough calculating to possibly find the answer myself, so my apologies for that, I'm really not too sure how to approach th

计算单元格大小并绘制(与之间的线)他们

我想绘制一个网格,并在单元格中绘制东西(为了保持容易,只需填充它们)。 总的来说,我只是在一些面板尺寸下工作得非常好,单元距离它应该放置的位置大约1个像素(重叠线)。 TBH我没有做足够的计算来自己找到答案,所以我很抱歉,我真的不太清楚如何处理这个“错误”。 无论如何,这是代码: public class Gui extends JFrame { public static void main(String[] args) { new Gui().setVisible(true); } public Gui(

How to use Hibernate eqOrIsNull()

I have two rows in MySQL like this +---------+---------+ | foo | bar | +---------+---------+ | | NULL | | | | +---------+---------+ Where empty are empty strings "" . Now I want to get both of them. I use Criteria and Restrictions.eqOrIsNull() on both columns, but it always returns only one row. The code is like this criteria.add(Restrictions.e

如何使用Hibernate eqOrIsNull()

我在这里有两行MySQL +---------+---------+ | foo | bar | +---------+---------+ | | NULL | | | | +---------+---------+ 空是空字符串"" 。 现在我想要得到他们两个。 我在两列使用Criteria和Restrictions.eqOrIsNull() ,但它总是只返回一行。 代码就是这样 criteria.add(Restrictions.eqOrIsNull("foo", "")); .add(Restrictions.eqOrIsNull("bar", ""));

Warn developer to call `super.foo()` in java

Lets say I have these two classes, one extending the other public class Bar{ public void foo(){ } } public class FooBar extends Bar { @Override public void foo(){ super.foo(); //<-- Line in question } } What I want to do is warn the user to call the super-class's method foo if they haven't in the override method, is this possible? Or is there a way

警告开发人员在java中调用`super.foo()`

可以说我有这两类,一类延伸到另一类 public class Bar{ public void foo(){ } } public class FooBar extends Bar { @Override public void foo(){ super.foo(); //<-- Line in question } } 我想要做的是警告用户调用超类的方法foo如果它们没有在覆盖方法中,这是可能的吗? 或者有什么方法可以知道,使用反射,如果我将类类传递给超类,那么覆盖其超类方法的方法会调用原始方法?

Regex fails to capture all groups

Using java.util.regex (jdk 1.6), the regular expression 201210(d{5,5})Test applied to the subject string 20121000002Test only captures group(0) and does not capture group(1) (the pattern 00002 ) as it should, given the code below: Pattern p1 = Pattern.compile("201210(\d{5,5})Test"); Matcher m1 = p1.matcher("20121000002Test"); if(m1.find()){ for(int i = 1; i<m1.groupCount(); i++){

正则表达式无法捕获所有组

使用java.util.regex (jdk 1.6),应用于主题字符串20121000002Test的正则表达式201210(d{5,5})Test仅捕获group(0)并且不捕获group(1) (模式00002 )因为它应该,给定下面的代码: Pattern p1 = Pattern.compile("201210(\d{5,5})Test"); Matcher m1 = p1.matcher("20121000002Test"); if(m1.find()){ for(int i = 1; i<m1.groupCount(); i++){ System.out.println("number = "+m1.group(i));

Confused about Matcher group in Java regex

I have the following line, typeName="ABC:xxxxx;"; I need to fetch the word ABC , I wrote the following code snippet, Pattern pattern4=Pattern.compile("(.*):"); matcher=pattern4.matcher(typeName); String nameStr=""; if(matcher.find()) { nameStr=matcher.group(1); } So if I put group(0) I get ABC: but if I put group(1) it is ABC , so I want to know What does this 0 and 1 mean? It will

在Java正则表达式中对Matcher组感到困惑

我有以下线路, typeName="ABC:xxxxx;"; 我需要取ABC字, 我写了下面的代码片断, Pattern pattern4=Pattern.compile("(.*):"); matcher=pattern4.matcher(typeName); String nameStr=""; if(matcher.find()) { nameStr=matcher.group(1); } 所以如果我把group(0)放到ABC:但是如果我把group(1)放到ABC ,所以我想知道 这个0和1是什么意思? 如果有人能够用很好的例子来解释我会更好。 正则表达式模式包含:在其

Backtrack in Possesive Quantifier

Earlier I posted a question about regex which resulted in stackoverflow error in java. My Regex was greedy and many commented to use possessive quantifier in regex. So, I started learning Possessive quantifier in regex. I tried to match string between double quotes. My regex is "([^\"]|\.)++" I tried to match the string "Hello I am " chitti" While matching there was backtracks. I tested

在Possesive Quantifier中回溯

之前我发布了一个关于正则表达式的问题,这导致了java中的stackoverflow错误。 我的正则表达式很贪婪,很多评论说在正则表达式中使用占有量词。 所以,我开始学习正则表达式中的Possessive量词。 我试图在双引号之间匹配字符串。 我的正则表达式是 "([^\"]|\.)++" 我试图匹配字符串 "Hello I am " chitti" 虽然匹配有回溯。 我使用http://regex101.com/#PCRE进行了测试。 正则表达式的链接是REGEX 101 LINK 有人可