PHP在后台进程完成后启动脚本?(PHP Launch script after background process completes?)
我正在用PDF2SWF转换PDF并用XPDF索引..用exec ..只有这样才需要执行时间非常高。
是否有可能将其作为后台进程运行,然后在完成转换后启动脚本?
I am converting a PDF with PDF2SWF and Indexing with XPDF.. with exec.. only this requires the execution time to be really high.
Is it possible to run it as background process and then launch a script when it is done converting?
原文:https://stackoverflow.com/questions/2414498
最满意答案
从Java 5中的ArrayList开始,如果数组具有正确的大小(或更大),则该数组将被填充。 所以
MyClass[] arr = myList.toArray(new MyClass[myList.size()]);
将创建一个数组对象,填充它并将其返回到“arr”。 另一方面
MyClass[] arr = myList.toArray(new MyClass[0]);
将创建两个数组。 第二个是长度为0的MyClass数组。因此,对象的对象创建将立即被抛出。 就源代码而言,编译器/ JIT不能优化这个,因此它不会被创建。 另外,使用零长度对象会导致toArray() - 方法中的转换。
看到ArrayList.toArray()的源码:
public <T> T[] toArray(T[] a) { if (a.length < size) // Make a new array of a's runtime type, but my contents: return (T[]) Arrays.copyOf(elementData, size, a.getClass()); System.arraycopy(elementData, 0, a, 0, size); if (a.length > size) a[size] = null; return a; }
使用第一种方法,以便只创建一个对象并避免(隐含但仍然昂贵)的铸件。
Counterintuitively, the fastest version, on Hotspot 8, is:
MyClass[] arr = myList.toArray(new MyClass[0]);
I have run a micro benchmark using jmh the results and code are below, showing that the version with an empty array consistently outperforms the version with a presized array. Note that if you can reuse an existing array of the correct size, the result may be different.
Benchmark results (score in microseconds, smaller = better):
Benchmark (n) Mode Samples Score Error Units c.a.p.SO29378922.preSize 1 avgt 30 0.025 ▒ 0.001 us/op c.a.p.SO29378922.preSize 100 avgt 30 0.155 ▒ 0.004 us/op c.a.p.SO29378922.preSize 1000 avgt 30 1.512 ▒ 0.031 us/op c.a.p.SO29378922.preSize 5000 avgt 30 6.884 ▒ 0.130 us/op c.a.p.SO29378922.preSize 10000 avgt 30 13.147 ▒ 0.199 us/op c.a.p.SO29378922.preSize 100000 avgt 30 159.977 ▒ 5.292 us/op c.a.p.SO29378922.resize 1 avgt 30 0.019 ▒ 0.000 us/op c.a.p.SO29378922.resize 100 avgt 30 0.133 ▒ 0.003 us/op c.a.p.SO29378922.resize 1000 avgt 30 1.075 ▒ 0.022 us/op c.a.p.SO29378922.resize 5000 avgt 30 5.318 ▒ 0.121 us/op c.a.p.SO29378922.resize 10000 avgt 30 10.652 ▒ 0.227 us/op c.a.p.SO29378922.resize 100000 avgt 30 139.692 ▒ 8.957 us/op
For reference, the code:
@State(Scope.Thread) @BenchmarkMode(Mode.AverageTime) public class SO29378922 { @Param({"1", "100", "1000", "5000", "10000", "100000"}) int n; private final List<Integer> list = new ArrayList<>(); @Setup public void populateList() { for (int i = 0; i < n; i++) list.add(0); } @Benchmark public Integer[] preSize() { return list.toArray(new Integer[n]); } @Benchmark public Integer[] resize() { return list.toArray(new Integer[0]); } }
You can find similar results, full analysis, and discussion in the blog post Arrays of Wisdom of the Ancients. To summarize: the JVM and JIT compiler contains several optimizations that enable it to cheaply create and initialize a new correctly sized array, and those optimizations can not be used if you create the array yourself.
相关问答
更多-
java list.toArray求解[2023-09-16]
定义一个字符串类型数组ss,大小为list的大小。定义一个泛型 数组obj,数组内容为list的内容。用一个for循环一次在控制台打印出obj数组的内容。 -
关于java中toArray的问题[2023-09-15]
Object[] toArray() 按适当顺序(从第一个到最后一个元素)返回包含此列表中所有元素的数组。 T[] toArray(T[] a) 按适当顺序(从第一个到最后一个元素)返回包含此列表中所有元素的数组;返回数组的运行时类型是指定数组的运行时类型。 -
为什么这里的自我是MyClass?(Why here the self is MyClass?)[2021-10-14]
self范围: 在类定义中, self始终是class constants(instance of Class)本身。(实例方法除外)。 在实例方法中, self是该类常量的实例,它只调用相应的方法。 p RUBY_VERSION class Foo def self.talk p "here SELF is-> #{self}" end def display p "here SELF is-> #{self}" end p "here SE ... -
没有太多差异,但这里有一些: class myClass extends myClass2 现在,这可能不是那么有问题,因为有myFunction.prototype = Object.create(myFunction2); ,但是,它可能有点复杂。 浏览器支持。 ECMAScript 6引入了类,但构造函数有多长时间了? 当然,相当长的一段时间。 某些浏览器可能不支持类。 总而言之,在我看来,你应该使用构造函数来支持浏览器。 但是如果你要在遥远的未来某个时候编写代码 - 类更整洁,更容易阅读。 Ther ...
-
从Java 5中的ArrayList开始,如果数组具有正确的大小(或更大),则该数组将被填充。 所以 MyClass[] arr = myList.toArray(new MyClass[myList.size()]); 将创建一个数组对象,填充它并将其返回到“arr”。 另一方面 MyClass[] arr = myList.toArray(new MyClass[0]); 将创建两个数组。 第二个是长度为0的MyClass数组。因此,对象的对象创建将立即被抛出。 就源代码而言,编译器/ JIT不能优 ...
-
如何使用ArrayAdapter
(How to use ArrayAdapter [2023-08-01]) 为您的课程实施自定义适配器: public class MyClassAdapter extends ArrayAdapter{ private static class ViewHolder { private TextView itemView; } public MyClassAdapter(Context context, int textViewResourceId, ArrayList items) { ... -
泛型,ToArray等(Generics, ToArray etc)[2021-12-11]
可能你应该看看Grasshopper并且不要重新发明轮子。 它是一个MSIL到Java字节码编译器,它是一个成熟的产品。 Probably you should have a look at Grasshopper and don't reinvent the wheel. It's a MSIL to Java bytecode compiler and it's a mature product. -
是否保证数组的最后4个元素始终为null? 基本上没有。 数组的最后四个元素将保留其先前的值。 如果该值恰好为null ,则它们将保持为null 。 例如: Integer[] array = Stream.of(7, 8).parallel().toArray(i -> new Integer[] {1, 2, 3, 4, 5, 6}); System.out.println(Arrays.toString(array)); 输出: [7, 8, 3, 4, 5, 6] 是否有可能必须使用toArr ...
-
第一个调用复制构造函数,临时对象作为参数 - MyClass()创建临时对象。 第二个调用默认构造函数。 实际上,在大多数情况下,它们被优化为相同的代码,但这是语义上的差异。 正如Negal所说,案件与POD类型略有不同; 当“MyClass”是POD时,第二个片段不会对mc值初始化,而首先是。 The first invokes copy constructor, with temporary object as parameter - MyClass() creates temporary. The s ...
-
实际上它根本不是指同一个类。 实际上,第二个EmployeeData不引用任何类。 这是通用名称。 您的ODataProxy定义了一个方法: public virtual IEnumerable
GetList (string query); ODataProxyStub使用以下ODataProxyStub实现: public override IEnumerable GetList (string query) 这不是 EmployeeD ...