Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Configure a suitable Jackson object pool when virtual threads are enabled #39783

Closed
mhalbritter opened this issue Feb 28, 2024 · 6 comments
Closed
Labels
status: declined A suggestion or change that we don't feel we should currently apply

Comments

@mhalbritter
Copy link
Contributor

The default pool uses ThreadLocals, which aren't a great fit when using virtual threads.

See https://twitter.com/jkuipers/status/1762505881000808516

@mhalbritter mhalbritter added this to the 3.3.x milestone Feb 28, 2024
@mhalbritter
Copy link
Contributor Author

A lock free pool will be the default with Jackson 2.17: https://twitter.com/cowtowncoder/status/1762668711063003623

@jkuipers
Copy link

jkuipers commented Mar 4, 2024

Note that my original attempt to set this up had a bug, as you shouldn't share a single JsonFactory between different ObjectMappers created by the builder that we're customizing. Creating the factory within the customizer does the trick:

@Bean @ConditionalOnProperty(name = "spring.threads.virtual.enabled")
Jackson2ObjectMapperBuilderCustomizer loomCustomizer() {
    return builder -> {
        var jsonFactory = JsonFactory.builder().recyclerPool(JsonRecyclerPools.sharedLockFreePool()).build();
        builder.factory(jsonFactory);
    };
}

@mhalbritter
Copy link
Contributor Author

mhalbritter commented Mar 4, 2024

Thanks for the update!

@MazizEsa
Copy link

@mhalbritter can I help out with this one? seems interesting.

@jkuipers
Copy link

Or update straight to Jackson 2.17 where the default changed to a lock-free pool: you only need explicit configuration for 2.16.x. Older versions don’t support this.

@mhalbritter
Copy link
Contributor Author

mhalbritter commented Mar 19, 2024

Thanks @jkuipers. The update to Jackson has been done already in #39920, so this issue should be obsolete.

FTR, here's the issue on Jackson's side: FasterXML/jackson-core#1117

@mhalbritter mhalbritter closed this as not planned Won't fix, can't repro, duplicate, stale Mar 19, 2024
@mhalbritter mhalbritter added status: declined A suggestion or change that we don't feel we should currently apply and removed type: enhancement A general enhancement theme: virtual-threads labels Mar 19, 2024
@mhalbritter mhalbritter removed this from the 3.3.x milestone Mar 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: declined A suggestion or change that we don't feel we should currently apply
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants