Здравствуйте, у меня возникла проблема. Я хотел вызвать метод для завершения процедуры (кварцевый планировщик) при нажатии кнопки (я создаю событие на контроллере) или при закрытии этапа, но мой метод не вызывается:
мой метод для закрытия моего планировщика
@Override
public void stop() {
System.out.println("xdx");
// pass true as a parameter if you want to wait
// for scheduled jobs to complete
// (though it will hang UI if you do that on FX thread).
try {
UsuarioDAO u = new UsuarioDAO();
u.setOffiline();
s.shutdown();
Platform.exit();
System.exit(0);
System.out.println("xd");
} catch (SchedulerException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
мой метод в контроллере (я вызываю это на кнопке)
@FXML
void leave(MouseEvent event) throws IOException {
Platform.exit();
}
уже протестировал отладку и не собирается закрывать мой метод
мой основной класс с моим планировщиком:
package ui.home;
import java.io.IOException;
import java.net.ServerSocket;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JOptionPane;
import org.quartz.JobBuilder;
import org.quartz.JobDetail;
import org.quartz.Scheduler;
import org.quartz.SchedulerException;
import org.quartz.SchedulerFactory;
import org.quartz.SimpleScheduleBuilder;
import org.quartz.Trigger;
import org.quartz.TriggerBuilder;
import org.quartz.impl.StdSchedulerFactory;
import dao.UsuarioDAO;
import dao.qtdRegistrosDAO;
import javafx.application.Application;
import javafx.application.Platform;
import javafx.event.EventHandler;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.input.MouseEvent;
import javafx.stage.Stage;
import javafx.stage.StageStyle;
import rotinas.BackupJob;
import rotinas.ChecarJob;
import views.Principal;
public class Main extends Application {
private static Stage stage;
private static qtdRegistrosDAO aQtdRegistrosDAO;
private Scheduler s;
public Main() {
}
@Override
public void start(Stage stage) throws Exception {
s = StdSchedulerFactory.getDefaultScheduler();
JobDetail j = JobBuilder.newJob(ChecarJob.class).build();
Trigger t = TriggerBuilder.newTrigger().withIdentity("CroneTrigger")
.withSchedule(SimpleScheduleBuilder.simpleSchedule().withIntervalInSeconds(60).repeatForever()).build();
try {
s.start();
try {
s.scheduleJob(j,t);
} catch (Exception e) {
e.printStackTrace();
}
} catch (SchedulerException se) {
se.printStackTrace();
}
Parent root = FXMLLoader.load(getClass().getResource("main.fxml")); //carrega fxml+
Scene scene = new Scene(root); //coloca o fxml em uma cena
stage.setResizable(false);
stage.setScene(scene); // coloca a cena em uma janela
stage.sizeToScene();
stage.show(); //abre a janela
setStage(stage);
}
private void blockMultiInstance() {
try {
ServerSocket serverSocket = new ServerSocket(9581);
} catch (IOException ex) {
JOptionPane.showMessageDialog(null, "Software em Uso", "Atenção", JOptionPane.WARNING_MESSAGE);
System.exit(0);
}
}
@Override
public void stop() {
System.out.println("xdx");
// pass true as a parameter if you want to wait
// for scheduled jobs to complete
// (though it will hang UI if you do that on FX thread).
try {
UsuarioDAO u = new UsuarioDAO();
u.setOffiline();
s.shutdown();
Platform.exit();
System.exit(0);
System.out.println("xd");
} catch (SchedulerException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
private void backup (){
try {
Scheduler sx = StdSchedulerFactory.getDefaultScheduler();
JobDetail jx = JobBuilder.newJob(BackupJob.class).build();
Trigger tx = TriggerBuilder.newTrigger().withIdentity("CroneTrigger2")
.withSchedule(SimpleScheduleBuilder.simpleSchedule().withIntervalInSeconds(60).repeatForever()).build();
try {
sx.start();
try {
sx.scheduleJob(jx,tx);
} catch (Exception e) {
e.printStackTrace();
}
} catch (SchedulerException se) {
se.printStackTrace();
}
} catch (SchedulerException ex) {
Logger.getLogger(Principal.class.getName()).log(Level.SEVERE, null, ex);
}
}
public static Stage getStage() {
return stage;
}
public static void setStage(Stage stage) {
Main.stage = stage;
}
public static void main(String[] args) {
launch(args);
}
}
мой контроллер:
package ui.home;
import java.io.IOException;
import java.net.URL;
import java.util.ResourceBundle;
import java.util.logging.Level;
import java.util.logging.Logger;
import de.jensd.fx.glyphs.fontawesome.FontAwesomeIconView;
import javafx.application.Platform;
import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.fxml.Initializable;
import javafx.scene.Node;
import javafx.scene.input.MouseEvent;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.HBox;
import javafx.scene.layout.Pane;
import javafx.scene.text.Text;
public class ControllerHome implements Initializable {
@FXML
private FontAwesomeIconView iconUser;
@FXML
private Text textUser;
@FXML
private BorderPane mainRoot;
@FXML
private FontAwesomeIconView iconReq;
@FXML
private Text textReq;
@FXML
private FontAwesomeIconView leaveIcon;
@FXML
private Text leaveTxt;
@FXML
void xx(MouseEvent event) throws IOException {
System.out.println("xd");
Pane content = FXMLLoader.load(getClass().getResource("/ui/user/mainContentUser.fxml"));
mainRoot.setCenter(content);
}
@FXML
void xxd(MouseEvent event) throws IOException {
System.out.println("xd");
Pane content = FXMLLoader.load(getClass().getResource("/ui/request/mainContentReq.fxml"));
mainRoot.setCenter(content);
}
@FXML
void leave(MouseEvent event) throws IOException {
Platform.exit();
}
@Override
public void initialize(URL location, ResourceBundle resources) {
}
}
мой архив планировщика:
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package rotinas;
import Conexao.ConnectionFactory;
import model.Alerts;
import model.Sessao;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import javafx.application.Platform;
import javafx.scene.control.Alert;
import javax.swing.JOptionPane;
import org.quartz.Job;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
/**
*
* @author Gabriel
*/
public class ChecarJob implements Job{
private Connection con;
public ChecarJob() {
this.con = new ConnectionFactory().getConnection();
}
public void execute(JobExecutionContext context) throws JobExecutionException {
System.out.println("Executou!");
try {
String verStatus = "SELECT COUNT(*) FROM equipamento_requisicao";
PreparedStatement stmt = con.prepareStatement(verStatus);
ResultSet rsStatus = stmt.executeQuery();
if(rsStatus.next()){
Alerts a = new Alerts();
int Resultado = rsStatus.getInt(1);
if(Resultado>Sessao.getInstancia().getQtdRegistroBD()){
Platform.runLater(() -> {
Sessao.getInstancia().setQtdRegistroBD(Resultado);
Alert alert = new Alert(Alert.AlertType.INFORMATION);
alert.setTitle("Atenção!");
alert.setHeaderText("Requisição adicionada!");
alert.setContentText("Uma nova Requisição foi adicionada.");
alert.showAndWait();
});
}
else if(Resultado<Sessao.getInstancia().getQtdRegistroBD()){
Sessao.getInstancia().setQtdRegistroBD(Resultado);
}
else{
}
}
stmt.close();
rsStatus.close();
}catch (Exception e) {
e.printStackTrace();
}
}
}