Userdefined functions and synchronized

45 views
Skip to first unread message

Olaf van der Meer

unread,
Feb 27, 2024, 10:38:01 AM2/27/24
to H2 Database
Hi,

I am using some user defined functions like this:

    public static boolean isPrime(int value) {
        return BigInteger.valueOf(value).isProbablePrime(100);
    }

    public static ResultSet query(Connection conn, String sql) throws SQLException {
        return conn.createStatement().executeQuery(sql);
    }

As for as I know it is better to avoid public static functions in a multi threaded application and it is betterto maken that methods synchronized like this:

    public synchronized static boolean isPrime(int value) {
        return BigInteger.valueOf(value).isProbablePrime(100);
    }

    public synchronized static ResultSet query(Connection conn, String sql) throws SQLException {
        return conn.createStatement().executeQuery(sql);
    }

Sometimes our server has a deadlock on some user defined functions. I think it is because I made them synchronized. 

What do you think?
Hope somebody give some advice about this. Thanks

Toolforger

unread,
Feb 28, 2024, 12:45:03 AM2/28/24
to h2-da...@googlegroups.com
Not an H2 question but a multithreading-in-Java question.
I have answers but don't want to go off-topic; anybody with an interest
in answers (including Olaf) can contact me directly via
toolf...@durchholz.org .

Regards,
Jo
Reply all
Reply to author
Forward
0 new messages