0

I have a Spring Neo4J server

I want to have an endpoint in this server that starts a thread to save tweets of a twitterstream to the neo4j database.

I also want to have an endpoint that stops this thread.

Is the best way to do this through the TaskExecutor object, or should I create a Runnable object and save it to the service bean, that I can interact with?

How would I do this in the context of a rest API endpoint in my Spring Data server?

bell_pepper
  • 187
  • 11

1 Answers1

0

The way they recommend is to use a shared variable as a flag which asks the background thread to stop. This variable can then be set by a different object requesting the thread terminate.

Coming from How do you kill a Thread in Java?

Qingfei Yuan
  • 1,196
  • 1
  • 8
  • 12