amitabh mehra

Ranch Hand
+ Follow
since Dec 05, 2006
Merit badge: grant badges
For More
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 amitabh mehra

Marc Cracco wrote:Might sound like a beginner question but why shouldn't you access a static variable from a local synchronized method?



Sorry if my previous post confused you. You are right, static variables can be accessed in local synchronized methods. But the lock should be on the Class again or some other static lock object. That is what i wanted to say in my previous post; but framed the sentence poorly
13 years ago
To access static variables from methods, those methods should be static. In that case, you need to synchronize on the Class.
13 years ago
I had already done that Ajay but i was looking for some application level code snippet / example to implement this

This is a problem of DB transactional concurrency control. It could be solved efficiently using optimistic concurrency control (by maintaining a version_id column in the DB table for Seats).



Ajay, can you please elaborate on this approach?
Thanks... that cleared my doubts!

Thread.State[] ts = e.values();


would return you an array of enum of Thread.State, and you are printing the same. These are not your "current thread" states.
Please check http://java.sun.com/j2se/1.5.0/docs/api/java/lang/Thread.State.htmlfor more info.
I am not able to understand the difference between the two. In case if I use an ArrayList of Future to store the Future returned to me by submitting the tasks through ExecutorService, is it not same as CompletionService implementation?

Also, I need help to identify why the following code does not exit after rendering the page.
Code description: To render a page, there are 2 main tasks: render text and render image (in code, 5 in numbers). For test purpose, I was creating Image data as simple print statement. Each image consists of random number (max of 5) of such statements.

1) notify() does not guarantee that consumer thread will be the next thread to run. It only guarantees that consumer thread is now *eligible to run*, but, since now both threads - Producer thread and Consumer thread are *eligible to run*, it all depends on the Thread Scheduler to schedule which thread should go next.

2) Consumer thread is not consuming in chaotic manner.

System.out.println(t.getName() + " consumed: " + prod.i);



You are printing the prod.i value. This will be the most recent one.

Better option to implement a Producer/Consumer problem would be to go for BlockingQueues else have some shared DataStructure in which Producer can go on inserting and consumer can pick items from there.

Ankur Jain Kothari wrote:ok...but what if i want to enter 1 first...then computer asking me to type the second number and then i type 2 and then Enter.? Can this be possible? how can we do this with getchar? here with getchar, it reads the first charachter and then 2nd charachter upon being called again...?

i hope my question is clear



any specific reason that you want only getchar()? you can very well use scanf or fscanf to get user input, one at a time, and parse them in whatever way you want or validate them before using them.
13 years ago
not directly.. but in implementation I think that this could be achieved... just an idea..
Use one lockObject ( create a class with some private member which will hold the next thread's name .. usual getter and setter methods)
Before starting all threads, set this member value to a given thread name, say "Thread 2"

In the run method, we will check if the current thread name is "Thread 2" then let it continue with its work else make it wait.
After completing its work, Thread 2 would set the member to next thread name... and then notify all.
Henry, can you elaborate how is that a spin wait. If i use thread.yield() will the thread not yield the cpu to other threads.
coming on top of this is another question which i m not sure is valid or not, still here it is - will yield() method, yield cpu to same and higher priority threads or any thread?
Okies Jaikiran, let me try in this forum also

i have already given the servlet mapping in my earlier post.
any help will be highly appreciated
14 years ago
Jaikiran

I can access the url http://localhost:8080/MyStore/MyStore/userRegister.html
on submitting the form, it should call a servlet... as I have already stated in my earlier post, but it fails giving 404.

it surely has to do something with the paths... ahhhhhhh.. this is so irritating dont know how to proceed....
14 years ago
@Jaikiran
did you get any clue from the log?

any help in this will be highly appreciated because i am stuck at this point and atmost i can do now is just read but cant implement and test...
14 years ago
sorry to update the thread so late... was not able to try the suggestions.

@Satya
tried after changing the application.xml.... nope, it didnt work.

@Jaikiran
Here is the console prints while bringing up the jboss server... might be too big... but was not sure what to leave out
(tried attaching it as txt / log file.. not allowed to upload)





I hope it will help to get where I am going wrong.
14 years ago