"Malicious apps have emerged as perhaps the most serious threat to mobile devices at the moment, and the major players, such as Apple and Google, have tried several different methods of preventing them from getting into their app stores and into the hands of users. Now, Google is taking one more step with the launch of a new service called the Private Channel for Google Apps, which gives enterprises and other organizations the ability to create private app stores and control the apps their users can download. Private Channel is essentially a way for organizations to stand up their own miniature app stores inside of Google Play--the main app store for Android devices--and publish apps to it. That gives these organizations the ability to point their users directly to the apps they want users to download for their Android devices. The new service will include some of the security features built into Google Play, most notably the anti-malware system and the ability to authenticate users."
2012年12月7日金曜日
Google Launches Private Android App Stores
ProcessBuilder - Start another process / JVM - HowTo?
I'm writing a network app, where each Client has a Singleton ClientManager. For testing, I would like to create several clients (each in their own VM / process) without starting the program by hand n-times.
The following two questions on stackoverflow already describe how-to do that:
- Is this really the best way to start a second JVM from Java code?
- Java: Executing a Java application in a separate process
My Code is based on these, but it's not working:
- The main program doesn't continue after spawn is called.
- The spawned code doesn't get executed.
Here's the complete code using ProcessBuilder:
public class NewVM { static class HelloWorld2 { public static void main(String[] args) { System.out.println("Hello World"); System.err.println("Hello World 2"); } } public static void main(String[] args) throws Exception { startSecondJVM(HelloWorld2.class, true); startSecondJVM(HelloWorld2.class, false); System.out.println("Main"); } public static void startSecondJVM(Class<? extends Object> clazz, boolean redirectStream) throws Exception { System.out.println(clazz.getCanonicalName()); String separator = System.getProperty("file.separator"); String classpath = System.getProperty("java.class.path"); String path = System.getProperty("java.home") + separator + "bin" + separator + "java"; ProcessBuilder processBuilder = new ProcessBuilder(path, "-cp", classpath, clazz.getCanonicalName()); processBuilder.redirectErrorStream(redirectStream); Process process = processBuilder.start(); process.waitFor(); System.out.println("Fin"); } }
What am I doing wrong???
Answers
I suggest you make HelloWorld2 a top level class. It appears java expects a top level class.
This is the code I tried.
class Main { static class Main2 { public static void main ( String [ ] args ) { System . out . println ( "YES!!!!!!!!!!!" ) ; } } public static void main ( String [ ] args ) { System . out . println ( Main2 . class . getCanonicalName ( ) ) ; System . out . println ( Main2 . class . getName ( ) ) ; } } class Main3 { public static void main ( String [ ] args ) { System . out . println ( "YES!!!!!!!!!!!" ) ; } }
- getCanonicalName and getName return different names. Which one is right? They are both wrong.
- Main3 works.