Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.programmer > #39737
| Path | csiph.com!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail |
|---|---|
| From | "Jeffrey H. Coffield" <jeffrey@digitalsynergyinc.com> |
| Newsgroups | comp.lang.java.programmer |
| Subject | Re: How to send a onetime scheduled task to executorService that has a repeptitive task ongoing |
| Date | Thu, 10 Mar 2022 07:21:18 -0800 |
| Organization | A noiseless patient Spider |
| Lines | 63 |
| Message-ID | <t0d51g$a82$1@dont-email.me> (permalink) |
| References | <e53511d0-8d10-4420-816e-b027569a85e5n@googlegroups.com> |
| Mime-Version | 1.0 |
| Content-Type | text/plain; charset=utf-8; format=flowed |
| Content-Transfer-Encoding | 7bit |
| Injection-Date | Thu, 10 Mar 2022 15:21:20 -0000 (UTC) |
| Injection-Info | reader02.eternal-september.org; posting-host="a75f41bc7f53d40b4fff87fcd6d83809"; logging-data="10498"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19QmMEV3XlPPmtix/OS3Epql6uEmqH1U5w=" |
| User-Agent | Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.6.0 |
| Cancel-Lock | sha1:sYH4OBcrITaCXh+HU4rvkeq2BrA= |
| In-Reply-To | <e53511d0-8d10-4420-816e-b027569a85e5n@googlegroups.com> |
| Xref | csiph.com comp.lang.java.programmer:39737 |
Show key headers only | View raw
On 03/10/2022 04:32 AM, mike wrote:
> Hi,
>
> We have implemented a "KeepAlive service" that we use over TLS.
>
> This service will send a message every 10 seconds to a server and if we get a response then we are ok and connection is considered ok.
>
> This is started using:
>
> KeepAlive keepAlive = new KeepAlive(this);
> keepAlive.init();
> future = scheduledTaskExecutor.newScheduledTask(keepAlive, 0, properties.getKeepAliveTime(),
> TimeUnit.SECONDS);
>
> Note: newScheduledTask() calls ScheduledFuture<?> future = executorService.scheduleAtFixedRate(runnable, delay, period, timeUnit);
>
> However we also have a method where we "instantly" want to find out if we are connected to the server.
>
> This is how it looks like:
>
> public synchronized boolean isConnected() {
>
> KeepAlive keepAlive = new KeepAlive(this);//create another keepAlive for same session.
> keepAlive.init();
>
> if (scheduledTaskExecutor!= null) {
>
> ScheduledFuture<?> scheduledTaskOnce = scheduledTaskExecutor.newScheduledTaskOnce(keepAlive, 10,
> TimeUnit.MILLISECONDS);
> try {
> Object object = scheduledTaskOnce.get();
> if (object == null) {
> logger.debug("Task has finished! {}", object);
> }
> } catch (InterruptedException | ExecutionException e) {
> logger.debug("We could not finished check of connection", e);
> }
> return keepAlive.isAlive();
> }
>
> Note: newScheduledTaskOnce() calls ScheduledFuture<?> future = executorService.schedule(runnable, delay, timeUnit);
>
> Q1: The KeepAlive hangs when doing it as a onetime task in the same executor. Any ideas why?
> Q2: How will a onetime task in same scheduledExecutor be handled when we have a repeatedly ongoing?
>
> br,
>
> //mike
>
Mike,
Without actually running the code or any deep analysis, my first
reaction to this problem would be to create a single method that does
one ping when called and exits with a boolean, possibly with a lock so
only one at a time can run. Then use the scheduler to run it every 10
seconds and set a static variable that other threads can check. Then if
you need an immediate test, just call the original method.
hth,
jeff
Back to comp.lang.java.programmer | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
How to send a onetime scheduled task to executorService that has a repeptitive task ongoing mike <mikaelpetterson@hotmail.com> - 2022-03-10 04:32 -0800 Re: How to send a onetime scheduled task to executorService that has a repeptitive task ongoing "Jeffrey H. Coffield" <jeffrey@digitalsynergyinc.com> - 2022-03-10 07:21 -0800 Re: How to send a onetime scheduled task to executorService that has a repeptitive task ongoing Stanimir Stamenkov <s7an10@netscape.net> - 2022-03-10 22:16 +0200
csiph-web