runtime

记使用WaitGroup时的一个错误

做~自己de王妃 提交于 2019-12-04 23:44:31
记使用WaitGroup时的一个错误 最近重构我之前写的服务器代码时,不当使用了WaitGroup,碰到了个错误,记录下. package main import ( "fmt" "sync" "time" ) func main() { var wg sync .WaitGroup wg .Add ( 1 ) f1 := func() { time .Sleep (time .Second * 2 ) fmt .Println ( "func()" ) wg .Done () } go f1() go f1() go f1() wg .Wait () fmt .Println ( "Done" ) } /* D:\test\>go run testwg2.go func() func() panic: sync: negative WaitGroup counter goroutine 22 [running]: runtime.panic(0x4a56e0, 0xc082000250) c:/go/src/pkg/runtime/panic.c:279 +0x11f sync.(*WaitGroup).Add(0xc0820045e0, 0xffffffffffffffff) c:/go/src/pkg/sync/waitgroup.go:64 +0x9a sync.(

Java执行Runtime.exec(shell)报Cannot allocate memory

江枫思渺然 提交于 2019-12-04 22:59:53
在Linux下用java的Runtime.getRuntime().exec(cmd)方式,执行shell脚本时,遇到“Cannot allocate memory”的错误。 网上查询资料整理如下: Cannot allocate memory 在Linux上调试一个比较复杂的Java程序,称为JavaA吧,JavaA会频繁的通过Process proc = Runtime.getRuntime().exec(cmd);调用一些外部程序。在系统负载和该程序占用内存都比较大的情况下,会出现调用失败的情况,错误信息是:"Cannot allocate memory"。 overcommit_memory 通过top发现,Java A大部分时间占用的内存实际并不多,但是占用的虚拟内存很大。马上修改该程序启动时的 JVM参数,将最大内存调的小一些,果然就不出错了。由于JavaA必须在内存中处理大量的数据,内存太小了就可 能处理不了,因此这么改是不可行的。 上网查的过程中,发现一些有趣的东西。Linux内核中可以设置内存的overcommit_memory属性( 设置方法:echo 1 > /proc/sys/vm/overcommit_memory ),意思是Linux 内核认为有些程序很保守,总是申请较多的内存,但实际并不使用,因此在设置overcommit后

How to load a JAR from Assets folder at runtime

一个人想着一个人 提交于 2019-12-04 22:37:42
问题 How to load a jar file from assets folder of android application during run time. Loading from assets folder is my requirement. Is there any way to do this. Please help .. 回答1: I got the answer.I am adding this answer here. Because this may be helpful to some others searching. There are steps to accomplish this. You have to make a copy of your JAR file into the private internal storage of your aplication. Using the dx tool inside the android folder, you have to generate a classes.dex file

what is the difference between running time ,complexity,compile time and execution time?

泪湿孤枕 提交于 2019-12-04 22:01:28
what is the difference between running time ,complexity,compile time and execution time? l have conflict between running time and time complexity and what is difference between them and execution time? Spektre What you are really asking is how to transform Big O Time complexity into runtime . That is not that easy as it seems at first. So take a closer look at complexities first, To make it more easy lets use this simple C++ example: int fact(int n) { if (n<=1) return 1; return n*fact(n-1); } Time vs. Space complexity (For starters I assume basic variables hence all complexities are the same

How can I create a MetadataWorkspace using metadata loading delegates?

☆樱花仙子☆ 提交于 2019-12-04 21:47:46
I followed this example Changing schema name on runtime - Entity Framework where I can create a new EntityConnection from a MetaDataWorkspace that I then use to construct a DbContext with a different schema, but I get compiler warnings saying that RegisterItemCollection method is obsolete and to "Construct MetadataWorkspace using constructor that accepts metadata loading delegates." How do I do that? Here is the code that is working but gives the 3 warnings for the RegsiterItemCollection calls. I'm surprised it works since warning says obsolete not just deprecated. public static

Get height for RecyclerView child views at runtime

╄→尐↘猪︶ㄣ 提交于 2019-12-04 19:02:45
I'm trying to make an expandable TextView that expands/collapses when a user presses a button. The TextView and ImageButton are in a CardView, which is added to a RecyclerView. The expand/collapse work nicely, but now I want to add the ImageButton only when the TextView height exceeds a certain maximum height. But when I evaluate the height in the LayoutManager's addView method, it returns 0, probably because the TextView does not have any text yet. Is there any callback method that I can override that is fired after the CardView gets it's new content, so that I can evaluate the height of the

Threads Java Inturrupts

自古美人都是妖i 提交于 2019-12-04 18:52:19
This is the second post I have on trying to end/quit threads using interrupts and dealing with Ctrl-c ends. I'm not sure I understand it but here is my best attempt. I need more clarity on the concepts, and please give code examples where you can. There are two classes, the main class Quitit and another class thething . The main class. When loading the program via the terminal (the case on Linux): Java -jar Quitit.jar When you Ctrl-c to close it am i correct in saying that you need to: Runtime.getRuntime().addShutdownHook() Your threads so that they are killed on shut down. Is this to correct

Create (LLBLGen) Linq query dynamicly with strings

喜你入骨 提交于 2019-12-04 17:14:27
We need to generate LINQ queries which are 100% unknown during coding (design time). This is because the logic is available in our framework which is 100% separated from any data projects. For data we use LLBLGen generated data access code. Normally by using invokes on the DLL, which we specify to the framework (not reference) we can create code to retrieve data. But now we need to do this by linq. How could we create a query like: var q = from customer in m.Customer select new { customer.Number, customer.City, customer.CountryEntity.Name }; from strings only. We would have 1 string called

Difference between O(m+n) and O(mn)?

隐身守侯 提交于 2019-12-04 17:08:35
I was trying to find the complexities of an algorithm via different approaches. Mathematically I came across one O(m+n) and another O(mn) approach. However I am unable to grasp or say visualize this. It's not like I look at them and get the "Ahh! That's what's going on" feeling! Can someone explain this using their own examples or any other tool? My recommendation for finding intuition is thought experiments as follows: First, realize that m and n are two different measurements of the input . They might be the lengths of two input streams, the lengths of sides of a matrix, or the counts of two

Get Java Runtime Process running in background

孤者浪人 提交于 2019-12-04 15:40:26
I'm writing a java application where I require to run a process in background throughout the lifetime of the running application. Here's what I have: Runtime.getRuntime().exec("..(this works ok).."); Process p = Runtime.getRuntime().exec("..(this works ok).."); InputStream is = p.getInputStream(); InputStreamReader isr = new InputStreamReader(is); BufferedReader br = new BufferedReader(isr); So, basically I print out every br.readLine() . The thing that I'm not sure about is how to implement this code in my application because wherever I put it (with Runnable), it blocks other code from