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

  • Home
  • SEARCH
  • 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 7892837
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T06:58:04+00:00 2026-06-03T06:58:04+00:00

Let us assume an object as follows: My Object { private String field1 =

  • 0

Let us assume an object as follows:

My Object { 
private String field1 = "";
private  String field2 = "";

/*getters and setters for field1 and field2 */

boolean isField1inDocument (String document) {
      if (document.indexOf(field1) > -1) return true;
      else return false;
 }

}

Is the method isField1inDcoument thread safe? I am worried that the boolean value returned by one thread may some how collide with the boolean value created by another thread executing the method at the same time. The documents being fed to the method are from individual threads and the documents themselves can’t collide. I know I can synchronize this method. I’m just trying to figure out if this is necessary.

  • 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-03T06:58:05+00:00Added an answer on June 3, 2026 at 6:58 am

    logically the behavior of isField1inDocument() is dependent on only the document (which you say is only owned by the thread), and the value of field1. You do have setters for field 1 so it’s possible to imagine a scenario where field1 is altered by a different thread while your current thread is doing your isField1inDocument() calculation, so that’s not thread safe.

    You could fix this by passing in the field1 value, e.g.

    boolean isField1inDocument (String document, String field1){...
    

    or by holding a private instance of the enclosing MyObject from the caller thread

    new MyObject().isField1InDocument(document)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Let's assume this class in C#: public class LimitedList<T> : List<T> { private int
When writing C++, let's assume the following line of code: Object* obj = new
Let's assume I have an array of object properties I'd like to access: $properties
Let's assume I have some MyObject obj object and want to access a property
x is an xts object full of data; let's assume OHLC data for the
Let's assume I have a jQuery object of a DIV element in body. I'd
Let's say we have two objects. Furthermore, let's assume that they really have no
Let's assume we have the following structure: index.php config.inc.php \ lib \ lib \
Let's assume that I am at manual A. I press enter and I am
Let's assume I browse a specific web page that uses JavaScript to update its

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.