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 7692459
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T20:51:27+00:00 2026-05-31T20:51:27+00:00

Currently I have an object which I receive from a server, this contains two

  • 0

Currently I have an object which I receive from a server, this contains two co-ordinates to be drawn to a canvas, which I can currently do in another class with hard coded co-ordinates.

My problem is that I cannot work out how to send the object (which is within a thread) to the second drawing class to be drawn.

  • 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-05-31T20:51:28+00:00Added an answer on May 31, 2026 at 8:51 pm

    An object is never within a thread. The best you can hope for is that only one thread references the object, and constant vigilance is required to keep it that way. Objects accessed by only one thread do not require anywhere near the thought and care that objects accessed by more than one thread do. But it’s real hard to keep objects on one thread, and you can’t do that here in any case.

    Your object from the server can be referenced from a public, static field in any class, and so be made available anywhere in your program (and to any thread). There has to be a more elegant way to make it available where needed–to encapsulate it properly–but this will do as a fallback solution.

    Then you have to take care of multi-threaded access. It sounds like your object can be made immutable. This just means that once you make it “public” by assigning it to it’s referencing field, you never change it again (even if it is theoretically possible to do so). This makes things simpler and faster. Create your received object and, when it is fully assembled, place it in its field. Make sure that field is marked volatile so any changes will be immediately seen elsewhere.

    Now your drawing class merely needs to look at the object when it needs it. However, before using it you want to copy the object to a local variable. The local variable will continue to point to the same object throughout the drawing process. The volatile field may change at any instant, continually refering to new or different objects. Using the local variable, your X and Y coordinates will always be consistent, if out-of-date. (Everything’s a bit out-of-date in a multi-threading system.) If you used the field, you could get the X from one object sent from the server and the Y from another. (The real fun with multi-threading comes when X * X, where the X is an integer, gives a value of 35–same X from two different objects. That and when if (aA != null) aA.doSomething() throws a null pointer exception. Using local variables prevents all this.)

    For now I think you can avoid synchronization and wait states. You might want to make your coordinate object truly immutable (with final fields) so other programmers (or even you after 6 months of doing other work) don’t change the code to modify the object on the fly. (If they/you do, they/you will need synchronization.)

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

Sidebar

Related Questions

Currently I have a DataModel object which contains my linq to sql classes(a dmbl
I'm developing an application which currently have hundreds of objects created. Is it possible
I currently have a collection with a HasChanges property on it (each object in
I currently have a Javascript function that uses a string to reference an object
I currently have a function: public static Attribute GetAttribute(MemberInfo Member, Type AttributeType) { Object[]
I have been working on keeping things object oriented for my project. Currently, I'm
I am currently writing an open source wrapper for a COM object. I have
I currently have a bunch of SQLCHAR objects from a database query. The query
We don't currently have our SQL Server objects in any form of source control.
I have a form JSP web page, this form contains multiple instances of the

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.