Any one know how to compiling and run huge no of java project in simultaneously(assume request comming every time) can i use for sun jdk for this situation. is there way to distributed compilation?

- 4,294
- 4
- 29
- 53

- 1,111
- 3
- 19
- 38
-
1What on earth would you want to do that for? – Dan Puzey Aug 18 '11 at 10:42
-
how do you track dependencies? – SJuan76 Aug 18 '11 at 10:43
-
Why do you need to compile your code for every request? – Thorbjørn Ravn Andersen Aug 18 '11 at 10:43
-
2He probably wants to provide binaries for all Java projects on GitHub ;) – Matt Aug 18 '11 at 10:48
2 Answers
You can use the ToolProvider
api to start a compilation programmatically. (see this tutorial for help)
With that as a starting point, you only need to create the proper abstraction to define what a project is (source folders, classpath etc.) and you have a thin frontend for compiling multiple projects.
I would probably use a ThreadPool to implement the actual compiling:
ExecutorService threadPool =
Executors.newFixedThreadPool(Runtime.getRuntime().availableProcessors());
Or if you can't use threads, use a pool of compilers (or compiler holders) with a library like commons / pool.
Either way, you can have this workflow:
- Request comes in
- transform request to project definition
- either request a free compiler or put the project in a queue
- compile
- return a handle to the compile job, so the client can poll the status asynchronously

- 292,901
- 67
- 465
- 588
Maven is starting to support it... but why? In the time it takes to do a parallel build of Firefox (a typical, large C++ app) on say... a Core 2 Duo, you probably could build at least 5,000 independent Java apps so long as your build process was properly glued together.
(In the time it takes to build about a half dozen or so large C++ objects for Firefox on my MacBook Pro, I could probably build the entire CAS webapp which has a few hundred Java classes and about 12-18 Maven submodules)

- 1
- 1

- 36,828
- 10
- 60
- 83