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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T07:08:13+00:00 2026-05-30T07:08:13+00:00

Using Java 1.6 and the AtomicLongArray, I’d like to copy the original AtomicLongArray into

  • 0

Using Java 1.6 and the AtomicLongArray, I’d like to “copy” the original AtomicLongArray into a new one. There is a constructor that takes an array (AtomicLongArray(long[])), so I thought I could just get the array from the original one and give it to the constructor.

Sadly, the actual long[] in the AtomicLongArray is private and there seem to be no getters for it. Is there any way to do this, meaning copy the values from one AtomicLongArray to another? I can’t create my own class based on this class, as the sun.misc.Unsafe class is not available to me.

This is needed because I’m going to iterate over the values, and I don’t want them modified by another thread during iteration. So I thought I could make a copy and use that for the iteration…

Thanks!
Phillip

  • 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-30T07:08:14+00:00Added an answer on May 30, 2026 at 7:08 am

    I suspect you have to create your own long[] and populate it first, or just iterate over the original:

    AtomicLongArray copy = new AtomicLongArray(original.length());
    for (int i = 0; i < copy.length(); i++)
    {
        copy.set(i, original.get(i));
    }
    

    Note that although each individual operation in AtomicLongArray is atomic, there are no bulk operations – so there’s no way of getting a “snapshot” of the whole array at time T. If you want that sort of behaviour, I believe you’ll need to use synchronization.

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

Sidebar

Related Questions

When using java threads, one has to take care of the basic problems that
Using java for Android development. I have an array that stores image resources. The
Using Java is there anyway to display a custom form/image that behaves similar to
Using java in one process, how can we create another process that is an
While using Java Options, i found they are of two types. One that has
Using Java 6 SE, I have a class that contains a Vector. There is
Using Java, how can I test that a URL is contactable, and returns a
Using Java (1.6) I want to split an input string that has components of
By using java reflection, we can easily know if an object is an array.
I'm using java, and I'm trying to make a JTextArea that is non-editable but

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.