@@ -65,30 +65,18 @@ public static void addWatermarkText() throws FileNotFoundException {
6565 String fileKey = uploadFileResult .getFileKey ();
6666 // perform tasks
6767 client .executeTask (taskId );
68- // create a ScheduledExecutorService with a fixed thread pool
69- ScheduledExecutorService executor = Executors .newScheduledThreadPool (1 );
70- // create an AtomicReference to hold the future
71- AtomicReference <ScheduledFuture <?>> futureRef = new AtomicReference <>();
72- // schedule a task to check the task status at a fixed rate
73- futureRef .set (executor .scheduleAtFixedRate (() -> {
74- // get task processing information
75- CPDFTaskInfoResult taskInfo = client .getTaskInfo (taskId );
76- // determine whether the task status is "TaskFinish"
77- if (taskInfo .getTaskStatus ().equals (CPDFConstant .TASK_FINISH )) {
78- System .out .println (taskInfo );
79- // get the final file processing information
80- CPDFFileInfo fileInfo = client .getFileInfo (fileKey );
81- System .out .println (fileInfo );
82- // if the task is finished, cancel the scheduled task
83- futureRef .get ().cancel (false );
84- }
85- }, 0 , 5 , TimeUnit .SECONDS ));
86- // schedule a task to cancel the scheduled task after 15 minutes
87- executor .schedule (() -> {
88- futureRef .get ().cancel (false );
89- }, 15 , TimeUnit .MINUTES );
90- // shutdown the executor
91- executor .shutdown ();
68+ // get task processing information
69+ CPDFTaskInfoResult taskInfo = client .getTaskInfo (taskId );
70+ // determine whether the task status is "TaskFinish"
71+ if (taskInfo .getTaskStatus ().equals (CPDFConstant .TASK_FINISH )) {
72+ System .out .println (taskInfo );
73+ // get the final file processing information
74+ CPDFFileInfo fileInfo = client .getFileInfo (fileKey );
75+ System .out .println (fileInfo );
76+ // if the task is finished, cancel the scheduled task
77+ }else {
78+ System .out .println ("Task incomplete processing" );
79+ }
9280 }
9381
9482 public static void addWatermarkImage () throws IOException {
@@ -116,30 +104,18 @@ public static void addWatermarkImage() throws IOException {
116104 String fileKey = uploadFileResult .getFileKey ();
117105 // perform tasks
118106 client .executeTask (taskId );
119- // create a ScheduledExecutorService with a fixed thread pool
120- ScheduledExecutorService executor = Executors .newScheduledThreadPool (1 );
121- // create an AtomicReference to hold the future
122- AtomicReference <ScheduledFuture <?>> futureRef = new AtomicReference <>();
123- // schedule a task to check the task status at a fixed rate
124- futureRef .set (executor .scheduleAtFixedRate (() -> {
125- // get task processing information
126- CPDFTaskInfoResult taskInfo = client .getTaskInfo (taskId );
127- // determine whether the task status is "TaskFinish"
128- if (taskInfo .getTaskStatus ().equals (CPDFConstant .TASK_FINISH )) {
129- System .out .println (taskInfo );
130- // get the final file processing information
131- CPDFFileInfo fileInfo = client .getFileInfo (fileKey );
132- System .out .println (fileInfo );
133- // if the task is finished, cancel the scheduled task
134- futureRef .get ().cancel (false );
135- }
136- }, 0 , 5 , TimeUnit .SECONDS ));
137- // schedule a task to cancel the scheduled task after 15 minutes
138- executor .schedule (() -> {
139- futureRef .get ().cancel (false );
140- }, 15 , TimeUnit .MINUTES );
141- // shutdown the executor
142- executor .shutdown ();
107+ // get task processing information
108+ CPDFTaskInfoResult taskInfo = client .getTaskInfo (taskId );
109+ // determine whether the task status is "TaskFinish"
110+ if (taskInfo .getTaskStatus ().equals (CPDFConstant .TASK_FINISH )) {
111+ System .out .println (taskInfo );
112+ // get the final file processing information
113+ CPDFFileInfo fileInfo = client .getFileInfo (fileKey );
114+ System .out .println (fileInfo );
115+ // if the task is finished, cancel the scheduled task
116+ }else {
117+ System .out .println ("Task incomplete processing" );
118+ }
143119 }
144120
145121}
0 commit comments