Nidhi Singhal

Ranch Hand
+ Follow
since Sep 19, 2004
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
In last 30 days
0
Forums and Threads

Recent posts by Nidhi Singhal




Generally, Thread.currentThread ( ) called from within the main method will return a handle to the main thread.

Thanks
Nidhi

I saw in many explanations that some people say that in sleep() or yield(),don't know which one, but in one of them the thread doesn't relinquish monitor lock.

My question is this, weather it is sleep or yield, first of all in case of syncronization it must relinquish the lock other wise how come the next thread enter in monitor and execute the syncronized method.

and one more confusion that the concept of object monitor only comes in case of synchronized methods or block?
Am I right.



Hi Punya,

Both yield() and sleep() will relinquish the monitor lock.

Yield() facilitates turn-taking among the equal priority threads. In case if no thread of the same priority is available, yield() will give the control back to same thread (as was executing earlier) almost immediately. So it seems as if the thread hasn't relinquished the monitor lock.

Sleep() is used to delay the execution of the thread for a specified amount of time. So definitely the monitor lock is relinquished.

Regarding your second Q - The object monitor comes into picture both in case of the synchronized method as well as the synchronized block. A monitor (lock) is like a privilege that only one thread can "own" at any point of time (i.e. only one thread can execute within the synchronized block at a time)

Thanks
Nidhi
[color=blue][/color]

Here, a new Runnable() is being passed to the executor.submit method so when the submit is called, the run() of the passed Runnable() will be executed which in turn will call con.process(). So actually a new thread is being started which executes the process() method of the Connection (con) object. And since con is final so con.process() cannot make any modifications to the Connection object. Synchronization is generally required to avoid data corruption (i.e maintain the data integrity). Here 'con' being final cannot cause data corruption hence it is not called from within a 'synchronized' context.

Thanks,
Nidhi
With hibernate, you can do batch updates - it reduces the database roundtrips.
Hi,

What is the exam fee for SCJP in India now a days? Can anyone tell.

Thanks,
Nidhi
Hi,

I have a utility for export and import of data. I am saving a file in excel format and then importing the same file to the database.
When I try to import the same exported file, I get IOException - Invalid Header signature. But, if I first open the exported file in MS excel and then do - save as (in excel format) and then Import that saved file, I don't get the error.
I find out that when I export the file, it saves the file in text format only along with with .xls extention. The MS Excel converts the text file into Excel while reading. But the file exported is not actually an excel worksheet so the Import of the same file does not works.
Is there any solution to this problem. I am already using response.setContentType("application/vnd.ms-excel");

Thanks,
Nidhi
16 years ago
Hi,

I am using hibernate and have a composite key in my table (made up of 3 coloumns). I want to use a sequence to generate values for one of the coloumn (which is a part of the composite key).

I am using the following way, but it's not working.

@GeneratedValue(strategy=GenerationType.SEQUENCE, generator="remitBchThresholdSeqNbr_SEQ")
@SequenceGenerator(name = "remitBchThresholdSeqNbr_SEQ", sequenceName="remitBchThresholdSeqNbr_SEQ")
@Column(name = "REMIT_BCH_THRESHOLD_SEQ_NBR", nullable = false, precision = 15, scale = 0)
public long getRemitBchThresholdSeqNbr() {
return this.remitBchThresholdSeqNbr;
}

Can anyone tell me that what is it that I am doing wrong here and how can I get this working.

Thanks,
Nidhi
Hi,

I am reading lines from a txt file and splitting words using StringTokenizer. My code is as below:

File:


BufferedReader in = new BufferedReader(new FileReader(FILENAME));
String line = in.readLine();
while(line != null) {
StringTokenizer tk = new StringTokenizer(line);
String first = tk.nextToken(),
second = tk.nextToken(),
third = tk.nextToken(),
fourth = tk.nextToken();

------
------
line = in.readLine();
}

In Line 1, there are 4 words - aaa, bbb, ccc, ddd which gets assigned to variables first, second, third and fourth.
In Line 2, there are only 3 words, The word that should be assigned to variable third is missing.

I want that the variable 'third' should not be assigned anything in the Line 2. But StringTokenizer treats all the spaces as delimiters.

How can this be done?

Thanks,
Nidhi

[ EJFH: Added "CODE" tags to preserve formatting in data file. ]
[ August 27, 2007: Message edited by: Ernest Friedman-Hill ]
17 years ago
Hi,

Does anyone have an idea about Chordiant? what is it and what is it used for? Is it in demand nowdays? Is it used for java/j2ee development?

Thanks,
Nidhi
17 years ago
Hi,

I am developing a web based application using weblogic workshop.
I have a custom control method that returns a HashMap of Bean class.
I am calling this method inside my jsp and referncing the fields using a repeater having datasource = {pageContext.mBean)
The problem comes when the form is submitted and I want to save the data in the database from the Java Page Flow method.
How can I get the data submitted from the form in the Java Page Flow method?

Thanks,
Nidhi
17 years ago
Hi,

I am creating a web service using Bea Workshop. In this I have 2 datasouces using different pools - one for fetching data for display and another for inserting some statistics in a table. I am getting the following exception:

java.sql.SQLException: Connection has already been created in this tx context for pool named ETNDBPOOL. Illegal attempt to create connection from another pool: wsloggerpool
at weblogic.jdbc.jts.Driver.getExistingConnection(Driver.java:512)
at weblogic.jdbc.jts.Driver.connect(Driver.java:143)
...............
.....

Is there some way I can use 2 differnt pools in my webservice?

Thanks,
Nidhi
17 years ago
No, there isn't anything inside run(). This is because my database code in a different class and I am not able to call the same from run(). I am using BEA workshop for development and all the db queries lies inside a database control which I am unable to call from run().
Hi,

I want make a thread that once started would periodically keep updating the database (after a specifed interval). I have the database logic in place.

My code is something like this:

t.start();

while(true)
{
System.out.println("Inside while(true) Loop");

if(t.isAlive() == true)
{
System.out.println("Inside t.isAlive() == true");
<update database>
}

try {
synchronized(t)
{
t.wait(3000);
}
} catch (InterruptedException e){
System.out.println("Thread interrupted" + e.toString());
}
}

The above code does not update the database but, when I comment out
while(true) loop, it updates the database. But I want the database to be updated periodically say after every 3000s.
How should I go about it?
Thanks. This is great.
But, if I want to call a method in the obj (the class loaded using Class.forName),
say:
dbLogger.logStat();
I cannot do that at the compile time. The code wouldn't compile.
Is there any way of calling a method within that class?

Thanks,
Nidhi
17 years ago
Hi,

In my application, I want to pick up the variable's type from the database and form a variable of that type.

For Ex.

private Controls.Custom.StatLogger DBLogger;
--------------------------

Here Controls.Custom.StatLogger is the type of variable DBLogger.
This type is stored in a database table. Once I pick this string from the database like
String str = "Controls.Custom.StatLogger";

the problem comes in constructing the varibale of that type:
private Controls.Custom.StatLogger DBLogger;

Can anyone help me out in this?

Thanks,
Nidhi
17 years ago