【发布时间】:2017-01-10 06:52:05
【问题描述】:
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();
它只执行一次。我需要连续执行这个问题,任何人都可以帮助我解决这个问题吗?
【问题讨论】:
-
"为了执行上述代码,我使用的是
.run();"。这不会在后台线程中运行任务:它将在当前线程上运行它(可能是 FX 应用程序线程,取决于您从哪里调用它)。您应该将其包装在Thread中并在线程上调用start(),或者将其提交给适当的Executor。