runtime

How do I get rid of Java child processes when my Java app exits/crashes?

淺唱寂寞╮ 提交于 2019-11-29 05:54:11
I launch a child process in Java as follows: final String[] cmd = {"<childProcessName>"}; Process process = Runtime.getRuntime().exec(cmd); It now runs in the background. All good and fine. If my program now crashes (it is still in dev :-)) the child process still seems to hang around. How can I make it automatically end when the parent Java process dies? If it helps, I'm using Mac OS X 10.5 VonC As you said, addShutdownHook is the way to go. BUT: There's no real guarantee that your shutdown hooks are executed if the program terminates. Someone could kill the Java process and in that case your

Why does this generics scenario cause a TypeLoadException?

我的梦境 提交于 2019-11-29 05:36:39
This got a bit long-winded, so here's the quick version: Why does this cause a runtime TypeLoadException? (And should the compiler prevent me from doing it?) interface I { void Foo<T>(); } class C<T1> { public void Foo<T2>() where T2 : T1 { } } class D : C<System.Object>, I { } The exception occurs if you try to instantiate D. Longer, more exploratory version: Consider: interface I { void Foo<T>(); } class C<T1> { public void Foo<T2>() where T2 : T1 { } } class some_other_class { } class D : C<some_other_class>, I { } // compiler error CS0425 This is illegal because the type constraints on C

How to get memory size of variable?

北战南征 提交于 2019-11-29 05:32:53
Does anybody know how to get memory size of the variable ( int , string , []struct , etc) and print it? Is it possible? var i int = 1 //I want to get something like this: fmt.Println("Size of i is: %?", i) //Also, it would be nice if I could store the value into a string You can use the unsafe.Sizeof function for this. It returns the size in bytes, occupied by the value you pass into it. Here's a working example : package main import "fmt" import "unsafe" func main() { a := int(123) b := int64(123) c := "foo" d := struct { FieldA float32 FieldB string }{0, "bar"} fmt.Printf("a: %T, %d\n", a,

Replace content of some methods at runtime

﹥>﹥吖頭↗ 提交于 2019-11-29 05:29:58
I would like to replace the content of some methods at runtime. I know I can use javassist for this but it does not work because the classes I would like to enhance are already loaded by the system classLoader . How can I do, to replace the content of a method at runtime ? Should I try to unload the class ? How can I do that ? I saw it was possible but I could not figure out how to do it. If possible, I would like to avoid using an external lib for this, I would like to code it my-self. More information: - The class I would like to enhance is contained in a framework (in a jar file) - My code

Is there kind of runtime C++ assembler library around? [closed]

六月ゝ 毕业季﹏ 提交于 2019-11-29 04:23:50
For my small hobby project I need to emit machine code from C++ program in runtime. I have base address 0xDEADBEEF and want to write something like this: Assembler a((void*)0xDEADBEEF); a.Emit() << Push(Reg::Eax) << Push(Reg::Ebx) << Jmp(0xFEFEFEFE); Inline assembler isn't my choice because generated machine code is dependent of the program state. Does anybody know any existing library for doing this? If no, would it be a good idea to develop one from scratch and make it open source? (I mean, will anybody ever use this library if it existed?) You could use Nicolas Capen's softwire . Its really

Android编译环境折腾记

六月ゝ 毕业季﹏ 提交于 2019-11-29 03:59:33
一、Ubuntu编译Android4.4.4 1.平台:realtek RTD2984(Android4.4.4)   第一次安装了ubuntu14.04.5,官网下载的iso,官网下的jar,编译android4.x需要安装jdk6,更高的版本会有问题,baidu到很多搭建环境的步骤,这个不多说,在win7下使用EasyBCD引导安装的ubuntu,1TB硬盘果断装了双系统,事实证明没删掉win7是个多么明智的决定,在jdk方面,android4.4比4.0要多配置一个javap,其他都一样 1 update-alternatives --install "/usr/bin/java" "java" "/usr/lib/jvm/jdk1.6.0_43/bin/java" 1 2 update-alternatives --install "/usr/bin/javac" "javac" "/usr/lib/jvm/jdk1.6.0_43/bin/javac" 1 3 update-alternatives --install "/usr/bin/javadoc" "javadoc" "/usr/lib/jvm/jdk1.6.0_43/bin/javadoc" 1 4 update-alternatives --install "/usr/lib/mozilla/plugins

is it possible to force a go routine to be run on a specific CPU?

三世轮回 提交于 2019-11-29 03:54:22
I am reading about the go package "runtime" and see that i can among other (func GOMAXPROCS(n int)) set the number of CPU units that can be used to run my program. Can I force a goroutine to be run on a specific CPU of my choice? In modern Go, I wouldn't lock goroutines to threads for efficiency. Go 1.5 added goroutine scheduling affinity, to minimize how often goroutines switch between OS threads . And any cost of the remaining migrations between CPUs has to be weighed against the benefit of the user-mode scheduler avoiding context switches into kernel mode. Finally, when switching costs are

Using AbstractRoutingDataSource to dynamically change the database schema/catalog

三世轮回 提交于 2019-11-29 03:02:03
问题 According to this article, you can use the AbstractRoutingDataSource from Spring Framework to dynamically change the data source used by the application. However, the data sources used are defined by configuration, instead of programmatically. Is there a way of configuring the data sources to be used at runtime? How scalable is this solution, i.e., what are the limitations in number of data sources? Thanks! 回答1: I have implemented this approach for 30 datasources and they are currently

Detect if a python module changes and then reload

一笑奈何 提交于 2019-11-29 02:56:47
So I'm developing a rather large python project with a number of modules. The "main" (runnable) module is a daemon (a Thrift daemon, actually) which calls off to other modules for its actual functionality. Starting up the daemon takes a long time because some of the modules have a rather lengthy and involved initialization processes. So when I start the daemon, I wait... let's say... 2 minutes for everything to load, which isn't too bad in the grand scheme of things. However for development it becomes a major pain because I need to restart the daemon EVERY TIME which has been wasting a lot of