0
private Task<Void> getTransferId = new Task<Void>() {
@Override
protected Void call() throws Exception {
Client client = ClientBuilder.newClient();
WebTarget webTarget = client.target(Constants.BASE_URL);
WebTarget helloworldWebTarget = webTarget.path(Constants.TRANSFER_FILE);
System.out.println(" checking working.....status");
Invocation.Builder invocationBuilder = helloworldWebTarget.request(MediaType.APPLICATION_JSON);
PostFileLog fileLog = new PostFileLog();
fileLog.setSenderId(myUuid);
fileLog.setReceiverId(clickedPossitionUuid);
fileLog.setFileName(fileName);
fileLog.setFileType(fileTypeInt);
fileLog.setFileSize(fileSizeFinal);
fileLog.setStatus(Constants.STATUS_PENDING);
fileLog.setFileDesc(Constants.NO_CAPTION);
Response response = invocationBuilder.post(Entity.entity(fileLog, MediaType.APPLICATION_JSON));
int status = response.getStatus();
PostFileLog reponceLog = response.readEntity(PostFileLog.class);
transferId = reponceLog.getUuid();
System.out.println(transferId + " fist sending TrasferId andstastus " + status);
return null;
}
};
爲了執行上面的代碼,我使用了.run();
它只執行一次。我需要持續執行這個問題,任何人都可以幫助我解決這個問題。javafx中的連續運行任務?
「對於執行上面的代碼,我使用'.RUN(); '」。這將不會在後臺線程中運行該任務:它將在當前線程上運行它(可能是FX應用程序線程,具體取決於您從哪裏調用它)。你應該把它封裝在一個'Thread'中,並在線程中調用'start()',或者將它提交給一個合適的'Executor'。 –