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();
它只执行一次。我需要不断地执行这个问题,任何人都可以帮助我解决这个问题的解决方案吗?
答案 0 :(得分:-1)
只需将代码置于while循环中,然后停止while循环
编辑您的代码检查此
boolean isStop=false;
private Task getTransferId = new Task()
{
@Override
protected Void call() throws Exception
{
while(!isStop){
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;
}
};
public void StopTask(){//To stop the task
isStop=true;
}