Giter VIP home page Giter VIP logo

Comments (10)

bytefish avatar bytefish commented on September 26, 2024 1

Yes, I think right now I am doing a hard shutdown on the HikariCP Connection Pool. I did a quick look at the HikariCP issue tracker and there is a way to soft evict the connections, when shutting down the Connection Pool. This might be worth implementing or adding to the article:

For the Tenant Name. I think I really should add something like a default tenant for the Spring Boot startup. See... I don't know how you start up your application. I went great length to prevent Spring Boot magic from making connections to the database, when starting the application. It's because Spring Boot tries to automagically find out, which database and dialect you are using, and other things... thereby making connections to a database.

But this connection at Startup, which Tenant Database should it use? The first?

So this can easily be fixed, if you are setting a Tenant Name explicitly for booting the application by using the ThreadLocal implementation I have provided. I will add this to the article, because it's not obvious at all. If you set this Tenant and Spring Boot makes a database connection at startup, it will use this tenant and not err out.

from bytefish.de.

bytefish avatar bytefish commented on September 26, 2024

The AsyncConfig is used for passing the tenant name into child threads when using the Spring @Async annotation.

from bytefish.de.

VivekMittals avatar VivekMittals commented on September 26, 2024

Thanks again Phillip, for the prompt reply.
As far as the way I started the application, it was really very simple and lazy way of using the STS IDE.. and run as spring boot application.. as there were junits running on start up. It created this problem.

Again, might be a silly one.. is it right to say we can ditch AsyncConfig if we want?
Cheers
Vicky

from bytefish.de.

VivekMittals avatar VivekMittals commented on September 26, 2024

Also as you mentioned I did the exact thing of specifying a default tenant and the problem goes away.
But then what I got confused with was that is this trigger necessary for web apps which we know will land via a typical Rest Api..

from bytefish.de.

bytefish avatar bytefish commented on September 26, 2024

Yes, you can safely remove it, when you don't plan to use @Async at all. Also make sure to delete the @EnableAsync annotation on the SpringBootApplication:

from bytefish.de.

VivekMittals avatar VivekMittals commented on September 26, 2024

Perfect Phillip,
I will try this sometime this week and let you know how that went!
Cheers!
Vicky

from bytefish.de.

bytefish avatar bytefish commented on September 26, 2024

Cool, feel free to add comments here!

from bytefish.de.

bytefish avatar bytefish commented on September 26, 2024

Funny, I just tried to make the application crash by not setting a Tenant on Startup. I know this was problematic, when I wrote the article. But with JDK14 I cannot make it crash, even though I removed all properties, that prevent initialization. Weird.

How did you manage to make it run into an error?

from bytefish.de.

VivekMittals avatar VivekMittals commented on September 26, 2024

Hey Phillip,

I tried running some tests which has a complex DB operation like some joins etc. With that only few of the tests complained about the mentioned scenario.

Also please note I didn't try the same with java 14.. but on an old JDK.

Regards,
Vicky

from bytefish.de.

bytefish avatar bytefish commented on September 26, 2024

I have just taken a look at the HikariCP implementation of the shutdown method:

It already calls HikaiPool#softEvictConnections() to provide a graceful shutdown. I don't think there is much more one can do when using HikariCP. The only thing I can think of is maybe calling HikariPool#softEvictConnections() yourself and give the Queries more time to finish, by introducing a wait delay.

from bytefish.de.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.