cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Community Tip - You can Bookmark boards, posts or articles that you'd like to access again easily! X

How do extensions know about Thingworx webapp unload?

VinayVaidya
11-Garnet

How do extensions know about Thingworx webapp unload?

So that they can initiate necessary cleanup, e.g. shutdown an executor

1 ACCEPTED SOLUTION

Accepted Solutions

The platform doesn't provide any way for extensions to hook into the servlet unload event directly.

That being said, what you should do is have your cleanup code tied into the logic for stopThing() if defined in a thing template, or stopSubsystem() if defined in a subsystem (the cleanup methods work as well).  When Thingworx is shut down it will attempt to stop all things and subsystems using those methods.  This also supports the scenarios where the thing or subsystem are stopped individually by the user.

View solution in original post

5 REPLIES 5
posipova
20-Turquoise
(To:VinayVaidya)

By the inheritance structure, running extensions are dependent on the platform rather  than the other way around. So, unless you have an external service to check for the platform unload, you cannot control the shutdown of an executor (through the extension reliability).

Very well. What is the advise to handle queues within extensions in that case? Does the platform provide for them? Alternately, could the platform register a ServletContextListener that can discover implementations of an interface and execute them?

The platform doesn't provide any way for extensions to hook into the servlet unload event directly.

That being said, what you should do is have your cleanup code tied into the logic for stopThing() if defined in a thing template, or stopSubsystem() if defined in a subsystem (the cleanup methods work as well).  When Thingworx is shut down it will attempt to stop all things and subsystems using those methods.  This also supports the scenarios where the thing or subsystem are stopped individually by the user.

Thanks, Jesse. That is what we did actually, it involved some reference counting but it worked. We also considered cleanUp, How does one make a decision vis-a-vis what goes into cleanUp vs StopThing, Looks like cleanUp checks isEnabled, So we thought stopThing to be safer, advice?

If your thing isn't enabled, then startThing() hasn't been called yet, so you probably haven't spun up your executor thread or thread pools yet.  So either method should be safe in that respect.

In terms of which is more correct, it really depends on the architecture of your extension.  If the threads are lightweight and can be spun up and down with little overhead (e.g., don't need to do any network handshakes), then having your logic in startThing and stopThing is fine.  If there is a lot of overhead in the startup process, then you'll want to split things out a bit.  You could create the executor thread and thread pool in initializeThing and have them begin processing in startThing, for example, then have the executor thread finish up processing and empty out the thread pool at stopThing and tear down the threads in cleanupThing.

Top Tags