小编Abd*_*dar的帖子

Java - 执行后不会删除Timer

我有一个应用程序,启动计时器以在用户操作上发送消息.在JDK分析器中,似乎所有其他线程在GC执行后被删除(我猜)但是创建的定时器没有被删除.可能会发生什么?

我的计时器:

/**
 * @param owner
 * @param added
 */
public static void splashParentWithAnimation(AnchorPane owner, Parent added,double posX,double posY) {
    // addParentWithAnimation(owner, added);
    owner.getChildren().add(added);

    AnchorPane.setLeftAnchor(added, posX);

    AnchorPane.setTopAnchor(added,  posY);

    FadeTransition ft1 = new FadeTransition(Duration.millis(300), added);
    ft1.setFromValue(0.0);
    ft1.setToValue(1.0);
    ft1.play();


    Timer messagePrinter = new Timer();
    messagePrinter.schedule(new TimerTask() {

        @Override
        public void run() {
            Platform.runLater(() -> {

                if (!owner.getChildren().contains(added))
                    return;

                FadeTransition ft1 = new FadeTransition(Duration.millis(300), added);
                ft1.setFromValue(1.0);
                ft1.setToValue(0.0);
                ft1.play();
                ft1.setOnFinished((e) -> {

                    if (owner.getChildren().contains(added))
                        owner.getChildren().remove(added);
                });

            });

        }
    },  1000);
}
Run Code Online (Sandbox Code Playgroud)

JDK分析器: 在此输入图像描述

是因为我使用静态方法还是应该自行销毁?

java timer timertask

9
推荐指数
1
解决办法
422
查看次数

对LocalDateTime进行排序

如何排序LocalDateTime对象?

我尝试了以下方法:

Comparator<Data> comparator = new Comparator<Data>() {
    @Override
    public int compare(final data o1, final data o2) {
        if (o1.getDate()== null || o2.getDate() == null)
            return 0;
        return o1.getDate().compareTo(o2.getDate());
    }
};

Collections.sort(comments, comparator);
Run Code Online (Sandbox Code Playgroud)

经过测试,我认为它根据日期排序,但时间部分(HH:MM:SS)被忽略了吗?

java sorting datetime jodatime java-time

2
推荐指数
2
解决办法
2万
查看次数

Java - get注释始终为null

我是注释的新手,我有使用自定义注释注释的FXMLController类,将这些类发送到工厂以从注释中获取值,但它始终为null~

注释:

public @interface FXMLController {

    String value() default "";

}
Run Code Online (Sandbox Code Playgroud)

用法:

@FXMLController(value=CommonConstants.SPLASH_SCREEN)
public class SplashScreenController{ ....... )
Run Code Online (Sandbox Code Playgroud)

获得价值:

Annotation annotation = controller.getAnnotation(FXMLController.class);
FXMLController fxmlController = (FXMLController) annotation;
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述

java annotations

1
推荐指数
1
解决办法
234
查看次数

标签 统计

java ×3

annotations ×1

datetime ×1

java-time ×1

jodatime ×1

sorting ×1

timer ×1

timertask ×1