Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Thread Pooling  RSS feed

 
Prabha Dhandapani
Ranch Hand
Posts: 70
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello Everybody,
I have a Java Program that reads an XML document ,parses it and loads the file into a database(table).This process is for every single XML File and there are 100's of files.So its takes a very long time to load all these documents.I need to multithread this process so that the XML's can be loaded simultaneously.I am kinda confused as to what I should do.I am new to thread porgramming and so read the Sun tutorial.What strategy or design shuld I follow to multiThread this process and what is the best solution. Also,I read about ThreadPooling which is my requirement because I use a database connection pool so I need to restrict the number of threads to say 5 that run to load the XML in the database.can somebody help me with a suitable solution???The requirement is not to have container managed pool.Would appreciate if someone can direct me to some source code that has implemented this concept so that I would be able to understand the process well.This is very very urgent.Looking for Rancher's help!
Many Thanks in advance,
Prabha
 
Adrian Yan
Ranch Hand
Posts: 688
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Seems that you are requesting two types of pool. One is database pooling, which creates a pool of database connections. The other is a file reading pool where you read more than 1 files at a time.
The database pool I use is from jakarta common project. DBCP
They also have a threadpool, althou I never used it. Threadpool
I use my own designed and implemented threadpool.
 
Prabha Dhandapani
Ranch Hand
Posts: 70
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Adrian!
I need to do a customized Thread pool for managing the threads that simultaneoulsy access XML Files.I have no idea of how to implement a Threadpool. I am looking for some source code that would show me a direction to implement my own ThreadPool.Would appreciate if u can give me some sort of a sample code that handles say 5 threads.Looking for some help!
Many Thanks,
Prabha
 
Adrian Yan
Ranch Hand
Posts: 688
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
try this one:
you might have to register tho:
Threadpool
You can also look at the code from jakarta common threadpool.
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The Jakarta Commons Threadpool is surprisingly and pleasingly simple. I'd be tickled if somebody tried it and told us all how it worked out.
JDK 1.5 will have this stuff built in, largely based on work by Doug Lea I think. You can google for Doug's thread utilities and find that they are not surprisingly and pleasingly simple. But they might be a lot more robust.
 
Adrian Yan
Ranch Hand
Posts: 688
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Stan, I was looking at it, and wanted try it out. But it appears that it's only in source code. I cvsed it, and having a hell of time trying to get it compiled. It seems that MAVEN is required. I spend the last hour trying to get it to work, to no avail.
Can you give me some pointers?
 
Jim Yingst
Wanderer
Sheriff
Posts: 18671
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
[Stan]: JDK 1.5 will have this stuff built in, largely based on work by Doug Lea I think.
In fact the 1.5 beta is available now. Check out the java.util.concurrent package. At the moment it seems to be missing a nice tutorial, but the components seem easy enough to use. Here's a simple demonstration:

[ February 24, 2004: Message edited by: Jim Yingst ]
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Wow, the Jakarta stuff requires Maven? I missed that. I just read the code online. Looked like only a couple very straightforward classes. I liked the blocking queue better than one we wrote a couple years ago.
 
Anthony Smith
Ranch Hand
Posts: 285
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The jakarata stuff does not require maven. Just get the jar. I use it.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!