agilemanoj kumar

Ranch Hand
+ Follow
since Mar 07, 2008
Merit badge: grant badges
For More
Bangalore, India
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
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 agilemanoj kumar

Hi,

I am running osgi container on my system.
I have written a class which is a bundle activator actually, which gets invoked after deploying into osgi container.
In this class, I want to call function containerDetails() which lists out all bundles and its details.
For example, if bundle is fragments and in INSTALLED state, my java code should get details of it.
I am able to get state of bundle(ACTIVE,INSTALLED,STARTING etc.) but unable to check if bundle is fragments or not.
Can anybody help me out to write a java code which checks if bundle is fragments or not?

--
Thanks,
Manoj
Hi All,

I have a scenario where I have to call multiple objects concurrently, and each object will call multiple other class's objects internally. After the execution of all child objects, it should return result back to parent object and finally, parent objects will return result back to Main thread. It is basically two level multi threading. I do not know which all things I should consider while implementing this scenario. Please help me out to solve this scenario. It would be better if anybody explain this scenario with a code example.

I have attached a picture which gives a clear understanding of the scenario.
Hi All,



I am unsuccessful to execute above code to get auth token for user "juddi" and getting error shown below:

Fault string, and possibly fault code, not set
at org.uddi4j.UDDIElement.<init>(UDDIElement.java:41)
at org.uddi4j.response.AuthToken.<init>(AuthToken.java:85)
at org.uddi4j.client.UDDIProxy.get_authToken(UDDIProxy.java:1628)
at CreateNewBusiness.main(CreateNewBusiness.java:25)


http://localhost:8080/juddi/happyjuddi.jsp UI is up and running perfectly.
I have attached screenshot to juddi webpage.

I am using juddi version 2 for UDDI4J, as UDDI4J is not compatible with uddi version 3.

Please help
12 years ago


I tried adding these two statements in main() method. But, it is giving me compile time error. What am I doing wrong??

--
Thanks,
Manoj Kumar
13 years ago
Hi,
I have an inner class(It is not a static class, just plain inner class) inside an outer class given below:



I would want to call display() method from static void main() method.
Coditions:
1. Do not insert/delete any code written above.
2. We have a flexibility to add any number of lines in main() method

How can we do that?

--
Thanks,
Manoj Kumar
13 years ago
Actually, I have never tried. I am just curious to know, how JVM will behave in such scenario?
13 years ago
How will I get the value associated with the key?
Suppose, my code is written like below:

Hashmap hm = new Hashmap();
hm.put("a","aValue"); // Suppose hashcode created for key "a" is 209
hm.put("b","bValue"); // Here hashcode created for key "b" is 209 as well.

Now, I want to retrieve value associated to key "b". I will call hm.get("b"). Since, hashmap searches key/value pair based on hashcode of key. Hashmap will find 209 hashcode for key "b". Since, same hashcode is found for key "a", Hashmap may return value "aValue" instead of expected value "bValue".

So, here is my question, I want to retrieve value associated with key. How will I do that?
Note: I have flexibility to override hashcode, so that I can return same hashcode for two different keys.
13 years ago
Hi,

I have weird question.

As we know, when we put key/value pair in hashmap, hashmap stores it using hashcode.
Suppose, Hashmap stores two different key/value pairs in it using same hashcode. When we call get method on these two different keys, what value will be returned from hashmap?

--
Thanks,
Manoj
13 years ago
No exceptions/errors found. I tried on windows xp with jdk 1.6
There is no difference between object lockObject and object of 'a' objectofa, if your concern is related to sequence of thread execution. You can synchronize your code using any type of object as long as this object is shared among all threads. In you code example, If I understood, both objects 'lockObject' and 'objectofa' is accessible and shared by Thread1 and Thread2. Hence, execution path will be fixed and predictable.
Your 4th question:

But If I run this code:
1. public class Main {
2. public static void main(String[] args) {
3. Account Mrxaccount = new Account("Mrxaccount");
4. Account Mrsxaccount = new Account("Mrsxaccount");
5. Mrxaccount.start();
6. Mrsxaccount.start();
7. //Mrxaccount.run();
8. //Mrsxaccount.run();
9.
10. Mrsxaccount.deduct(100);
11. Mrxaccount.deduct(100);
12.
13. }
14.
15.
16. }

public class Main { public static void main(String[] args) { Account Mrxaccount = new Account("Mrxaccount"); Account Mrsxaccount = new Account("Mrsxaccount"); Mrxaccount.start(); Mrsxaccount.start(); //Mrxaccount.run(); //Mrsxaccount.run(); Mrsxaccount.deduct(100); Mrxaccount.deduct(100); } }

It shows this:

ERROR
ERROR



Why?What happened that it shows ERROR?


Answer to your 4th question:
Put breakpoints at and and run your program in debug mode. You will see only one ERROR.
PS: It is hard to predict running sequence of threads. In your 4th question, Two threads are spawned and most of the time (say 99%) second thread is calling

System.exit(0);

not first thread. That's why you are seeing two ERROR almost all the time. Here, after execution of 'System.out.println("ERROR");' by first thread, second thread calls 'System.out.println("ERROR");' and 'System.exit(0);' almost all the time.
Your 3rd question is:
3-If I run this code:
1. public class Main {
2. public static void main(String[] args) {
3. Account Mrxaccount = new Account("Mrxaccount");
4. Account Mrsxaccount = new Account("Mrsxaccount");
5. //Mrxaccount.start();
6. //Mrsxaccount.start();
7. //Mrxaccount.run();
8. //Mrsxaccount.run();
9.
10. Mrsxaccount.deduct(100);
11. Mrxaccount.deduct(100);
12.
13. }
14.
15.
16. }

public class Main { public static void main(String[] args) { Account Mrxaccount = new Account("Mrxaccount"); Account Mrsxaccount = new Account("Mrsxaccount"); //Mrxaccount.start(); //Mrsxaccount.start(); //Mrxaccount.run(); //Mrsxaccount.run(); Mrsxaccount.deduct(100); Mrxaccount.deduct(100); } }

It does not show anything!


Answer to 3rd question:
Please see answer to 2nd question, my previous reply. Calling Mrxaccount.run() or Mrxaccount.deduct(100) method are same a like. They dont have to do anything with Threads.
Answer to 2nd question:
2-If I run this code without:
1. Mrxaccount.run();
2. Mrsxaccount.run();


In your Account class, variable 'total' is declared as private. It means, two different objects will have two separate copies of instance variable total.
In main () method, you have created two different objects Mrxaccount and Mrsxaccount. These two object are calling run() method in different stacks. Variable total is not shared between these two objects.
Remember, Just calling Mrxaccount.run() and Mrsxaccount.run(), does not creates thread here. These are just simple two objects.
That s why, When Mrxaccount.run() gets called, total = 100-100 = 0
And when Mrsxaccount.run() gets called, total = 100 - 100 = 0 (here total will be 100 not 0)
So, you wont see any message here