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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T07:41:33+00:00 2026-06-09T07:41:33+00:00

I am having a Server storing data from clients. Every Client works in his

  • 0

I am having a Server storing data from clients.
Every Client works in his own Thread and is having one Data-Object.
This Data-Object is a custom class, lets call is Data.java containing unspezific data, this could be some bytes but normally from around 100kb < Data < 2mb.
Now i have a backup-thread, iterating through the list of clients, parsing their data-object to xml using Xstream and storing this in a database.
But is this safe?
If the client is doing operations altering the Data while it is backed up (Assuming that clients send requests around every 0,1 seconds and that some request could endure around seconds altering the Data at all time in the process) this data could be corrupt.
What would be a good way to do it?

  • 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-09T07:41:35+00:00Added an answer on June 9, 2026 at 7:41 am

    You can lock the object with synchronized or a Lock whenever you change or read the objects. I would also use a boolean dirty; flag which is set to true whenever you alter it. That way your background thread only needs to save the objects which have changed.

    Since the client might be altering the data for a long period of time, I would consider using lock.tryLock() which allows you to try and get the lock without blocking so the thread can still “backup” objects which are not locked. You can always re-try on the next cycle.

    An example

    class Data{ 
        final Lock lock = new ReentrantLock();
        boolean dirty = false;
    
        public void setSomething(String a) {
            lock.lock();
            try {
                // modify the Data
                dirty = true;
            } finally {
                lock.unlock();
            }
        }
    
        public void backupData(Backup backup) {
           if (!lock.tryLock()) return;
           try {
               if (!dirty) return;
    
               backup.for(this);
    
               dirty = false;
           } finally {
               lock.unlock();
           }
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am getting JSON response from the server..Inside that JSON string i am having
We are having a client-server architecture where client goes offline when connects remotely to
I am currently writing an application having a client server architecture. The client is
I need to programmatically store data on the client side without having to transfer
I am building a server-client program with c and having some problen wtih sendina
So I'm having this code that processes what the client sends on a pattern.
i have a client server application showing where the clients are intended for touch
I'm having trouble returning data from my controller using an ajax post function. What
If I have pages having server-side code in code-behind, then I know that the
I've an asp.net page having a server side submit button and 2 textboxes which

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.