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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T02:54:30+00:00 2026-06-11T02:54:30+00:00

consider below code class Repository{ public static Item i; //Item is a type (class)

  • 0

consider below code

class Repository{
  public static Item i; //Item is a type (class)
  GetItem(){
    // initialize i if null. Read i from an xml file if the last write time of file is greater than last read time else return current i
    return i;
  }
  SaveItem(item){
    //save i;
    //write i to xml file
    i=item;
  }
}

class User{
  public static void Main(){
    Repository r = new Repository();
    r.GetItem().MakeChangesToItem(); //method inside item to make some changes
    r.SaveItem(r.GetItem());
  }
}

Is there any chance this code behaves sporadically. Apparently it does for me. Sometimes the changes are reflected in the static item sometime not. When i changed the Main method code to

Item i=new Repository().GetItem();
i.MakeChangesToItem();
r.SaveItem(i);

it works normally.
Has any one experienced this? Thanks

  • 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-11T02:54:31+00:00Added an answer on June 11, 2026 at 2:54 am

    Static means it is not tied to any instance, but is per-type instead. A common issue with static is threading. If you have multiple threads (for example, an ASP.NET or WCF application, or anything where you use threads/tasks/parallel yourself) then craziness can ensue as they all think they’re talking about different things, overwriting the same field.

    I would say static is very unsuitable for that field.

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

Sidebar

Related Questions

A bit of help please, consider the bit of code below. public class Widget
Consider code sniper below: package sync; public class LockQuestion { private String mutable; public
Consider the following code snippet below. class X { public String toString() { return
Consider the code below: #!/usr/bin/env python from PyQt4 import QtCore, QtGui import os,sys class
Consider the code below: public class Analyzer { protected Func f,fd; public delegate double
Consider the code below: <?php class Base { protected $name = Base; public function
Consider the sample code below: #include <iostream> using namespace std; class core { public:
Consider the JavaScript code below, inspired from the YUI documentation on YAHOO.lang.extend . In
Consider the below: public class DependencyA {} public class DependencyB {} public class DependencyC
Consider the example below: #include <iostream> using namespace std; class base { public: virtual

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.