Rocksolid Light

Welcome to RetroBBS

mail  files  register  newsreader  groups  login

Message-ID:  

BREAKFAST.COM Halted... Cereal Port Not Responding.


devel / comp.lang.java.programmer / How to send a onetime scheduled task to executorService that has a repeptitive task ongoing

SubjectAuthor
* How to send a onetime scheduled task to executorService that has amike
+- Re: How to send a onetime scheduled task to executorService that hasJeffrey H. Coffield
`- Re: How to send a onetime scheduled task to executorService that hasStanimir Stamenkov

1
How to send a onetime scheduled task to executorService that has a repeptitive task ongoing

<e53511d0-8d10-4420-816e-b027569a85e5n@googlegroups.com>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=78&group=comp.lang.java.programmer#78

  copy link   Newsgroups: comp.lang.java.programmer
X-Received: by 2002:a05:6214:f2f:b0:432:c4c9:9953 with SMTP id iw15-20020a0562140f2f00b00432c4c99953mr3524703qvb.113.1646915560709;
Thu, 10 Mar 2022 04:32:40 -0800 (PST)
X-Received: by 2002:a05:6870:e890:b0:da:52ca:41c1 with SMTP id
q16-20020a056870e89000b000da52ca41c1mr8316142oan.50.1646915560409; Thu, 10
Mar 2022 04:32:40 -0800 (PST)
Path: i2pn2.org!i2pn.org!weretis.net!feeder8.news.weretis.net!border2.nntp.dca1.giganews.com!nntp.giganews.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.java.programmer
Date: Thu, 10 Mar 2022 04:32:40 -0800 (PST)
Injection-Info: google-groups.googlegroups.com; posting-host=83.253.144.66; posting-account=1c_fOgoAAADuOXlL0A4-T9PUmVHtMSYd
NNTP-Posting-Host: 83.253.144.66
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <e53511d0-8d10-4420-816e-b027569a85e5n@googlegroups.com>
Subject: How to send a onetime scheduled task to executorService that has a
repeptitive task ongoing
From: mikaelpetterson@hotmail.com (mike)
Injection-Date: Thu, 10 Mar 2022 12:32:40 +0000
Content-Type: text/plain; charset="UTF-8"
Lines: 46
 by: mike - Thu, 10 Mar 2022 12:32 UTC

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

Re: How to send a onetime scheduled task to executorService that has a repeptitive task ongoing

<t0d51g$a82$1@dont-email.me>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=79&group=comp.lang.java.programmer#79

  copy link   Newsgroups: comp.lang.java.programmer
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: jeffrey@digitalsynergyinc.com (Jeffrey H. Coffield)
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>
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>
 by: Jeffrey H. Coffield - Thu, 10 Mar 2022 15:21 UTC

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

Re: How to send a onetime scheduled task to executorService that has a repeptitive task ongoing

<t0dma9$fu4$1@dont-email.me>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=80&group=comp.lang.java.programmer#80

  copy link   Newsgroups: comp.lang.java.programmer
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: s7an10@netscape.net (Stanimir Stamenkov)
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 22:16:09 +0200
Organization: A noiseless patient Spider
Lines: 80
Message-ID: <t0dma9$fu4$1@dont-email.me>
References: <e53511d0-8d10-4420-816e-b027569a85e5n@googlegroups.com>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Thu, 10 Mar 2022 20:16:09 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="9dce16ea476e09591008f7342e1364dd";
logging-data="16324"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX183374qE4FED9hTSQL3Z+iY"
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:68.0) Gecko/20100101
SeaMonkey/2.53.11
Cancel-Lock: sha1:i+edCRxcFcfpxH8WTl7RSj5YAI4=
In-Reply-To: <e53511d0-8d10-4420-816e-b027569a85e5n@googlegroups.com>
X-Face: (5^k'[FumQ)D<K'|!m[XIPQMS<@?TEyc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tE1T
f5GswMmX9O/NynJNf0paLN6jokDBiFOoKqrHTp7oHyariRuYqKcgQnf/rHXqdy09qCgpEPGo
24xyZ+qpipuQrbYHxaadjEWmiy9iyYTPrXVxjg70Z52HqN7NzKNjvjADaBFQkd7DW98GqSd+
bpzpzw==
Openpgp: preference=signencrypt
 by: Stanimir Stamenkov - Thu, 10 Mar 2022 20:16 UTC

Thu, 10 Mar 2022 04:32:40 -0800 (PST), /mike/:

> 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.
>
> 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.
>
> ScheduledFuture<?> scheduledTaskOnce = scheduledTaskExecutor.newScheduledTaskOnce(keepAlive, 10,
> TimeUnit.MILLISECONDS);
> Object object = scheduledTaskOnce.get();
>
> 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?

You haven't specified what is your ScheduledExecutorService
configuration/implementation.

I'm using the following in a real world project:

import java.util.concurrent.*;

public static void main(String[] args) throws Exception {
ScheduledExecutorService executor =
Executors.newSingleThreadScheduledExecutor();

executor.scheduleAtFixedRate(slowTask("Regular", 10),
0, 100, TimeUnit.MILLISECONDS);

ScheduledFuture<?> oneOff = executor
.schedule(slowTask("One-off with delay", 50),
100, TimeUnit.MILLISECONDS);
oneOff.get();

executor.execute(slowTask("Immediate one-off", 100));

Future<?> oneOff2 = executor
.submit(slowTask("Immediate one-off with result", 100));
oneOff2.get();

Thread.sleep(50);

executor.shutdown();
}

static Runnable slowTask(String name, long timeMillis) {
return () -> {
System.out.append(name).print("...");
try {
Thread.sleep(timeMillis);
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
throw new IllegalStateException(e);
}
System.out.println(" done.");
};
}

That is a single-thread scheduled executor [1] to serialize both:

* A task scheduled to run at regular intervals; and
* One-off executions.

> 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?

One of my uses actually triggers one-off task at the end of the
scheduled task, also – not just externally submitted. Not sure what
"onetime task in the same executor" in you case means.

[1]
https://docs.oracle.com/javase/8/docs/api/java/util/concurrent/Executors.html#newSingleThreadScheduledExecutor--

--
Stanimir

1
server_pubkey.txt

rocksolid light 0.9.81
clearnet tor