我有一个应用程序,启动计时器以在用户操作上发送消息.在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)
是因为我使用静态方法还是应该自行销毁?
如何排序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)被忽略了吗?
我是注释的新手,我有使用自定义注释注释的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)