The most straightforward way is to pass it via a constructor to (for example) your Jersey resource class. For example:
environment.jersey().register(new HelloWorldResource(managedExecutorService)); Ryan On Tue, Aug 24, 2021 at 3:04 PM Kode Tester <[email protected]> wrote: > In DW Core ( > https://www.dropwizard.io/en/latest/manual/core.html#managed-objects), > the sample code below talks about configuring Executor Service in > Application run method. > > If I want to access executorService in my class, what is the right way to > get a reference? > > > <<<<<<snip>>>>>> > > It should be noted that Environment has built-in factory methods > for ExecutorService and ScheduledExecutorService instances which are > managed. These managed instances use InstrumentedThreadFactory that > monitors the number of threads created, running and terminated > > public class MyApplication extends Application<MyConfiguration> { > @Override > public void run(MyConfiguration configuration, Environment environment) { > > ExecutorService executorService = environment.lifecycle() > .executorService(nameFormat) > .maxThreads(maxThreads) .build(); > > ScheduledExecutorService scheduledExecutorService = > environment.lifecycle() .scheduledExecutorService(nameFormat) > .build(); > } > } > > > > > -- > You received this message because you are subscribed to the Google Groups > "dropwizard-user" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to [email protected]. > To view this discussion on the web visit > https://groups.google.com/d/msgid/dropwizard-user/e19b94f3-7627-431b-a9a8-6ef015777b39n%40googlegroups.com > <https://groups.google.com/d/msgid/dropwizard-user/e19b94f3-7627-431b-a9a8-6ef015777b39n%40googlegroups.com?utm_medium=email&utm_source=footer> > . > -- You received this message because you are subscribed to the Google Groups "dropwizard-user" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/dropwizard-user/CAFVYhL88CZ5YSdv%3D%2BE6ByHp6PsSvXo-u%3DTrB%3D3UVtaiS47hbnw%40mail.gmail.com.
