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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T08:39:21+00:00 2026-05-30T08:39:21+00:00

As an experiment I ran the following code snippet (simplified): public class SGamePlay extends

  • 0

As an experiment I ran the following code snippet (simplified):

public class SGamePlay extends Activity implements View.OnClickListener
{
    Calendar GlobalCal = null;

    public void onCreate(Bundle savedInstanceState) 
    {
        GlobalCal = Calendar.getInstance();
    }

    long time_in_ms()
    {
        long ans = -1;
        long ans2 = -1;

        Calendar LocalCal = Calendar.getInstance();

        ans = LocalCal.getTimeInMillis();

        ans2 = GlobalCal.getTimeInMillis();

        Log.e("game","ans="+ans+" ans2="+ans2);

        return ans;
    }
    // much more code here...
}

The time_in_ms() function is called from a sub thread. The problem is that while ans appears to be a correct, constantly updating value, ans2 appears frozen at its initial value. How could this be?

EDIT: I need to resolve this issue because I want to reduce the need for garbage collection in my program.

  • 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-30T08:39:22+00:00Added an answer on May 30, 2026 at 8:39 am

    Calendar is to be thought of as a “mark” in a calendar. It’s more like a point in time, than an interface to the current time. (Why else would it have set-functions?)

    So, the reason why ans2 is “frozen” is because GlobalCal.getTimeInMillis(); will always refer to the time when you called Calendar.getInstance() in the constructor (which you did once).

    I need to resolve this issue because I want to reduce the need for garbage collection in my program.

    Is the garbage collection the bottle neck of your program? Is the number of Calendars the bottle neck of the GC? Have you profiled your program?

    Never mind… call System.currentTimeMillis instead.

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

Sidebar

Related Questions

I just did a little experiment: public abstract class MyClass { private static int
Just to experiment assembly in C++, I tried the following, which is causing the
I started Solr and ran the following query: curl http://localhost:8983/solr/dataimport?command=full-import&commit=true I then checked the
I experimented the following code list<int> a ={1,2}; list<int> b ={3,4}; a.erase(b.begin()); for (auto
This is just an experiment code. struct B { virtual B* operator -> ()
While looking at the Timer documentation I ran across the following example with this
Here's a little experiment I ran in an Oracle database (10g). Aside from (Oracle's)
I am writing a text Editor application. As an experiment I ran the application
As an experiment i am trying to write the following program which allows me
While trying out an experimental UINavigationController-based iPhone application, I ran into a problem when

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.