Intro

We are close to completing this round of applications that expose or make our in-house component or service (the Shape Calculator) available. Here is where we left off, and if you have not been following this series from the start, you'll probably want to refer back to all the previous articles, since we are going to be working with the Shape Calculator component we wish to expose.

Add Calculator Operations

Let's open the RequestResponseController, and inside the "pending()" method (the method mapped to "/pending" ), let's add the code to get back all Pending Requests from the Shape Calculator:

Right away, my Eclipse complains. We need to inform our webapp project of the shape-calc project; go to this webapp's properties and:

(The name of the Eclipse web app project that we began with in previous articles is "webapp-dep-on-shape-calc-jpa-hibernate," but because I am writing these articles in pieces, I need to have and keep intermediate projects along the way, thus a different name)

Once we add the child project, Eclipse only complains of a missing "calculator" member, so let's add it:

@Autowired
private ShapeCalculatorService calculator;

This time, no compile errors, so I do a Build.Deploy.Start (BDS) and... I see this in the Eclipse console output:

I'm not going to use Eclipse's method of adding the project dependency. Rather, let's add this to the web app's POM: Our web app knows nothing of the existence of the Shape Calculator, of course, because that is a different project.

So this time, the web app project is aware of the shape-calc project, and Spring is doing its thing. However, we need our MySQL database to be up and running.

I'm going to be using Cygwin command-line terminals rather than Windows. I previously covered all this in the articles leading up to this one, so I won't go into any detail here.

OK, I think we're good now. Let's try to restart the server... and we have a clean start, and the web page tabs work.

Correcting Server Shutdown Process

When we shut down the server, though, we notice a problem. Two problems, actually.

Sep 09, 2016 11:29:43 AM org.apache.catalina.loader.WebappClassLoaderBase clearReferencesJdbc
WARNING: The web application [webapp-p3] registered the JDBC driver [com.mysql.jdbc.Driver] but failed to unregister it when the web application was stopped. To prevent a memory leak, the JDBC Driver has been forcibly unregistered.
Sep 09, 2016 11:29:43 AM org.apache.catalina.loader.WebappClassLoaderBase clearReferencesThreads
WARNING: The web application [webapp-p3] appears to have started a thread named [Abandoned connection cleanup thread] but has failed to stop it. This is very likely to create a memory leak. Stack trace of thread:
java.lang.Object.wait(Native Method)
java.lang.ref.ReferenceQueue.remove(ReferenceQueue.java:143)
com.mysql.jdbc.AbandonedConnectionCleanupThread.run(AbandonedConnectionCleanupThread.java:43)

The idea here is that when shutting down the server, we have not dealt correctly with cleaning up some resources. Let's take a side-trip from completing our web app and focus on these issues.

The Shape Caculator itself uses an ExecutorService thread pool.

And it also has a DataSource.

And we have the MySQL driver.

We need to handle those in that same order.

Before we get to them, though, let's learn some more about how a Spring-based web app starts up and shuts down.

Next...

This is going to get a bit lengthy, and it deserves another article, so stay tuned for the next one. After we handle the topic of shutting down, we'll continue with completing the web app.