Go Back   TechArena Community > Software > Software Development
Become a Member!
Forgot your username/password?
Register Tags Active Topics RSS Search Mark Forums Read SiteMap

Tags: , , ,

Sponsored Links



How do you synchronize java?

Software Development


Reply
 
Thread Tools Search this Thread
  #1  
Old 28-11-2009
Member
 
Join Date: Nov 2009
Posts: 50
How do you synchronize java?

Hi,
I am working on java project in my company. While working on project yesterday our team leader asked me How do you synchronize java? I am not able to explain exactly how it works that's why I decided to taking your help. If you have any idea about this please help me.
Thank you.
Reply With Quote
  #2  
Old 28-11-2009
Zecho's Avatar
Member
 
Join Date: May 2008
Posts: 2,267
Re: How do you synchronize java?

The java programming language supports two basic process one is synchronize method and other one is synchronize statement. If you want to make synchronize method just add synchronized keyword to it.

Following is the example of it.


Code:
 public class SynchronizedMethod
         {
        private int p = 0;

        public synchronized void incre() {
            p++;
        }

        public synchronized void decre() {
            p--;
        }

        public synchronized int value() {
            return p;
        }
    }
Reply With Quote
  #3  
Old 28-11-2009
Reegan's Avatar
Member
 
Join Date: Oct 2005
Posts: 2,299
Re: How do you synchronize java?

synchronize is a type of command-line utility for doing one-way directory or for performing file synchronization. If source is match with the target then target is modified.synchronize process runs on any other Operating System if there is Java Runtime Environment. synchronize is free software that made from java.
Reply With Quote
  #4  
Old 28-11-2009
opaper's Avatar
Member
 
Join Date: May 2008
Posts: 2,362
Re: How do you synchronize java?

Two threads must not executed synchronized method simultaneously.

like following example:
synchronized ( Object1 )
{
/* Some important code */
}

Example of synchronized instance method:

synchronized doityourself()
{
/*Some important code */
}

Example of synchronized syntactic shorthand:

doityourself()
{
synchronized( this )
{
/* Some important code */
}
}


Example of protecting static variables
synchronized ( getClassdata() )
{
/*Some important code */
}
__________________
The FIFA Manager 2009 PC Game
Reply With Quote
  #5  
Old 28-11-2009
MindSpace's Avatar
Member
 
Join Date: Feb 2008
Posts: 1,832
Re: How do you synchronize java?

Synchronized Class Method:
Code:
class class1{
   static synchronized type MN1() {
      statement b
   }
}
Synchronized Instance Method:
[code]

class class2 {
synchronized type MN2() {
statement b
}
}




Synchronized Statement:
Code:
class class3 {
   type MN3() {
      synchronized (obj1) {
         statement b
      }
   }
}
Reply With Quote
  #6  
Old 28-11-2009
Modifier's Avatar
Member
 
Join Date: Jan 2008
Posts: 1,502
Re: How do you synchronize java?

Example of synchronize Methods :

Code:
public class synchronizeMethods
{
   public synchronized void IM1 ()
   {
      important  code.
   }

   public synchronized void IM2 ()
   {
     important  code.
   }

   public static synchronized void CM ()
   {
      important  code.
   }
}
Code:
public class synchronizeStatements
{
   public void instanceMethod1 ()
   {
      //  code for setup

      synchronized (this)
      {
         // Update your file.
      }

      // code for cleanup.
   }

   public void IM2 ()
   {
      // code for setup

      synchronized (this)
      {
         // Read from this file.
      }

      // code for cleanup.
   }
}
Reply With Quote
Reply

  TechArena Community > Software > Software Development


Thread Tools Search this Thread
Search this Thread:

Advanced Search


Similar Threads for: "How do you synchronize java?"
Thread Thread Starter Forum Replies Last Post
Synchronize Iphone 4 to a PC or Mac Jokull Portable Devices 4 03-11-2010 08:40 AM
How to synchronize with Syncplicity cyber-noob Tips & Tweaks 2 09-08-2010 05:57 PM
MP4's Audio is not able to Synchronize Udbala Portable Devices 3 21-05-2010 03:56 PM
Synchronize an iterator in java Remedy Software Development 5 18-02-2010 01:28 AM
How To Synchronize Two Pcs? Albert E Windows Software 3 28-02-2008 08:51 PM


All times are GMT +5.5. The time now is 11:52 AM.