|
| |||||||||
| Tags: java, java language, java programming, synchronize |
![]() |
| | Thread Tools | Search this Thread |
|
#1
| |||
| |||
| 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. |
|
#2
| ||||
| ||||
| 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;
}
} |
|
#3
| ||||
| ||||
| 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.
__________________ Grand Theft Auto 4 PC Video Game |
|
#4
| ||||
| ||||
| 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 |
|
#5
| ||||
| ||||
| Re: How do you synchronize java?
Synchronized Class Method: Code:
class class1{
static synchronized type MN1() {
statement b
}
} [code] class class2 { synchronized type MN2() { statement b } } Synchronized Statement: Code:
class class3 {
type MN3() {
synchronized (obj1) {
statement b
}
}
} |
|
#6
| ||||
| ||||
| 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.
}
} |
![]() |
|
| Thread Tools | Search this Thread |
| |
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 |