Vib Mator

Greenhorn
+ Follow
since Oct 21, 2010
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
2
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Vib Mator

hi
i have a program

which has two synchronized methods.
but both make a call to same non synchronized method.
this non synchronized method makes changes to the list of data that i have.
is it thread safe??

synchronized method1(obj o1){

//some other data
makeFirst(o1)
}

synchronized method2(obj o2){

//some other data
makeFirst(o2)
}

makeFirst()
{

makes changes to same list of data

}


printdata()
{iterate over list and print values
}

do i need to make 'makechange() and printdata()' methods synchronized as well ???




makeFirst is a private method...which is just called by these two methods.

while the PrintData is called publicly.

wouldnt i require to synchronize this makeFirst method because at a time when both synchronized methods will be calling this method.
the two different threads may each may be calling one of the methods

like
Thread1 calls synchronized method1
Thread2 calls synchronized method2

but these two methods call the makeFirst method. wihch is accessing the same list of data.
there is nothign that is synchronizing access to the makeFirst method.
ie. nothing is making these two calls from two threads to be synchronized.

just a psuedocode below.

thread1.synchronized method1.makeFirst()
thread2.synchronized method2.makeFirst()

both sharing same data and making changes to it..

but if i make makeFirst as synchronized, it will make only one of these methods to access the data and make changes to the list at one instance of time.
Am i thinking on the right way.?







<File ref for file_to_be_moved>.renameTo(new File(<dest_folder File ref>,<File ref for file_to_be_moved >.getName()));

is what would be the right thing to do.

13 years ago
make use of list method
it returns an array
so you can always check the length parameter

int num_of_file=new File(<directory path>).list().length ;
13 years ago
I have two XML files of sizes greater than 2gb each and of same stucture.

I need to compare the files and print the same data between the two.

How do I read both of the files in memory to compare?
13 years ago
System.exit(n) terminates the JVM.... so its the proper way to exit the program explicitly. you can always provide a number n..
n =0 is generally used to show successful completion..
if you know a point where in your program may differ from what you want to do....
say for a condition where you think you would never reach....if it reaches there.
you can always return n with any value such as 1.... by looking at value of n , you can determine whether the program completely successfully or not...

13 years ago
using this ^[^\\s]+@(([^\\s].*\\.[a-zA-Z]+)|(localhost))$

\\s also includes underscore
And i wonder if domain names have underscores in them

so \\s check after @ would cosider _ even if websites do not have underscores in their names...
Correct me if i m wrong about my assumption for domain names wid underscores

^[^\\s]+@(([^\\s&&[^_]].*\\.[a-zA-Z]+)|(localhost))$
13 years ago