Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8715391
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T05:49:58+00:00 2026-06-13T05:49:58+00:00

I have a class that needs to provide a fast classification service. For example,

  • 0

I have a class that needs to provide a fast classification service. For example, I want to write code like “classify(“Ac Kd Kh 3c 3s”)” that quickly returns TWO_PAIR. (This isn’t the application but you get the jist)

Because I need the classification to be quick I want to precompute, and then store, a look-up table that lists the classification output for all possible inputs. In the interest of time I want to parallelize this precomputation. HOWEVER, attempting to use “classifySlowly” from a 2nd thread creates a deadlock.

public class Classifcation Service {
  enum CLASS {TYPE_A, TYPE_B, ...};

  static CLASS[] preComputedClassLookUpTable;

  static {
    preComputedClassLookUpTable = constructLookUpTableInParallel();
  }

  //Note: using this method from with constructLookUpTableInParallel causes deadlock
  private static CLASS classifySlowly(Object classifyMe) {
    //do time intensive work to classify the input
    // -- uses no other methods from this class
    return classification;
  }

  public static CLASS classify(Object classifyMe) {
    //use the lookup table to do a quick classification
    return classification;
  }   
}

So my question is: Is there a way to precompute this lookup table IN PARALLEL from within the static initalizer block?

The only (poor) alternative I see is to switch from:

preComputedClassLookUpTable = constructLookUpTableInParallel();

To:

preComputeClassLookUpTable = loadLookUpTableFromFile();
if(preComputedClassLookUpTable == null) {
  System.out.println("WARNING:  Construction incomplete, Must call computeAndSaveLookUpTableFile();}
}

I thought this would be too much but here is the implementation of constructLookUpTableInParallel

private static CLASS[] constructLookUpTableInParallel() {

  //build a collection of Runnables by iterating over all possible input Objects
  //wrap each possible input in an anonymous Runnable that calls classifySlowly.

  //submit the collection of Runnables to a new ExecutorService
  //process runnables...
  //shutdown executor service      
}

////////END OF POORLY WORDED ORIGINAL QUESTION ///////////

The solution that works somewhat cleanly is splitting the classifySlowly(Object classifyMe) and classify(Object classifyMe) methods into two different classes.

This will allow the (first) class that contains “public static CLASS classifySlowly(Object classifyMe)” to be fully loaded by the time the (second) class that contains “public static CLASS classifyQuickly(Object classifyMe)” needs to use the classifySlowly method. Now, that the 2nd static inialization block don’t require any of its own static methods it can be fully parallelized.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T05:49:59+00:00Added an answer on June 13, 2026 at 5:49 am

    “So my question is: Is there a way to precompute this lookup table IN PARALLEL from within the static initalizer block?”

    Yes, it’s practically certain there is a way. Just new the array and launch a Runnable for each array element. Give each Runnable reference to the array, and index it is computing, then have it do the computing without locking, then lock when assigning result to the array element.

    Note/disclaimer: this answer is based on the rather incomplete information given in the question…

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a class that needs to be initialized but it's namespaced like this:
I have a generic class that needs to limit an enum depending on the
I have a Base class that needs a Generic type. That can be either
I have a utility class that needs to work on a generic Class but
I have a situation where I have an instanced class that needs to call
I have a non-Activity class (let's call it NonActivity) that needs to post a
If you have data for a class that will be modified and needs to
In Python, say I have some class, Circle, that inherits from Shape. Shape needs
I'd like to provide an accessor on a class that provides an NSInputStream for
I have a web service that needs to be protected from unauthorized users. I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.