Greetings;

So I have an update on this issue.   YAY! :D

I have a service that creates a little bit of metadata in the database
for sending large amounts of emails/sms (for speed, the user doesn't
have to wait for the population of the queue).

I create a servlet on startup that polls the table, then uses the
metadata to populate another table with the communications details
(addresses, message bodies, subjects, as required).

I'm using a timer to do this.  Asynchronous makes it fast for the user
and more fault tolerant during processing.  All in all, a great
algorithm that takes very little code and is scalable and fast.  w00t!

On startup, Tomcat deploys the poller servlet, but here is where
things get weird.

When the poller tries to get its first database connection, it times
out with this error:
"Cannot create PoolableConnectionFactory (Could not create connection
to database server. Attempted reconnect 3 times. Giving up."

After it times-out, startup resumes regularly and the other services
in the application come alive and are poolable to the database?!

I have a code sample below that is from the init method of the
servlet.  Note that I'm using the MBeanServer code to get the port
automatically so I don't have to change a configuration from dev to
production (I couldn't find an easier more reliable way to do this).
The code times out on the database connection attempt here: connection
= ConnectionFactory.getConnection();

Note - if I plug in ethernet, it's a snappy startup.  If I unplug
ethernet and wait for this servlet init to time-out, then the DBCP is
eventually configured and working great, and I can access all of the
other data-driven services in my app with the network cable unplugged
and wireless turned off.

Here is the code in the poller servlet that is offensive.
ConnectionFactory is wrapping standard JNDI DBCP lookups:

-----

            MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
            Set<ObjectName> objs = mbs.queryNames(new ObjectName(
                "*:type=Connector,*"),
                Query.match(Query.attr("protocol"), Query.value("HTTP/1.1")));
            String hostname = InetAddress.getLocalHost().getHostName();
            InetAddress[] addresses = InetAddress.getAllByName(hostname);
            HashMap me = null;
            String host = "";
            for (Iterator<ObjectName> i = objs.iterator(); i.hasNext();)
            {
                ObjectName obj = i.next();
                String scheme = mbs.getAttribute(obj, "scheme").toString();
                if(!scheme.equals("http"))
                {
                    log.warn("Invalid scheme encountered [" + scheme
                        + "] looking for another connector.");
                    continue;
                }
                else
                {
                    log.info("Found connector.");
                }

                String port = obj.getKeyProperty("port");
                for (InetAddress addr : addresses)
                {
                    // first in the list, will always be at least one
                    host = SMSSendBindIp + ":" + port;

                    scheduler = Executors.newSingleThreadScheduledExecutor();
                    scheduler.scheduleAtFixedRate(new HttpRequestTimer(
                        scheme + "://"
                        + host + "/somecontexturlandparams"),
                        0, 5, TimeUnit.SECONDS);

                    log.info("Scheduling sms queue processor.");

                    try
                    {
                        connection = ConnectionFactory.getConnection();

-----

Thanks and have a good one,

John



On Thu, Apr 19, 2018 at 1:13 PM, Mark Thomas <ma...@apache.org> wrote:
> On 19/04/18 18:37, John Dale wrote:
>> Greetings;
>>
>> I have a 2006 era macbook pro with the latest osx.
>>
>> I run MySQL, which binds to localhost just fine when the network cable
>> is unplugged and wireless turned off.
>>
>> Tomcat makes it through most of its startup, but hangs before
>> completion
>
> If you take 3 thread dumps ~5 seconds apart you should be able to see
> where it is hanging. If you can tell us that we might be able to provide
> you with some ideas to fix it or additional debug options to try.
>
> For the record I have an OSX development laptop and I've never seen this
> issue. Admittedly the hardware is rather newer.
>
> Mark
>
>
>
>> and requests from the browser hang and eventually timeout.
>>
>> I've tried 127.0.0.1, 0.0.0.0, and omitted for the "address" attribute
>> of the connector.
>>
>> With no network, Tomcat successfully makes a connection to MySQL to
>> creates the connection pool, but hangs.  There are no errors.
>>
>> I am running debugging transport.
>>
>> My hosts file is stock, fine.
>>
>> As soon as I plug in a network cable or connect to wireless, the
>> server comes-up fine and I can access it on 127.0.0.1 or the static ip
>> assigned to either the wireless interface or the hard LAN.
>>
>> I. am.  stumped.  Please help.  I need to be able to demo my project
>> without being connected to the network.
>>
>> :\
>>
>> I've been dealing with this issue for awhile, and I'm finally fed-up with it.
>>
>> We want offline and we want it .. NOW! ;)
>>
>> Thanks folks.
>>
>> Sincerely,
>>
>> John from Spearfish, SD
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org
>> For additional commands, e-mail: users-h...@tomcat.apache.org
>>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org
> For additional commands, e-mail: users-h...@tomcat.apache.org
>

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org
For additional commands, e-mail: users-h...@tomcat.apache.org

Reply via email to