Call Perl from java, mainly for regular expression matching

前端 未结 2 1738
旧巷少年郎
旧巷少年郎 2021-01-16 01:41

I\'d like to execute Perl code efficiently from Java. The purpose of the Perl is mainly to perform regular expression matching (in some tests it Perl was more efficient than

2条回答
  •  抹茶落季
    2021-01-16 01:45

    It would have to be a very special case indeed where executing Perl from Java to process a regular expression yields better performance. Regardless of whether Perl can process individual regular expressions faster than Java or not, there is an overhead to starting Perl up from Java, as well as a Thread overhead in Java to correctly manage a forked process.

    Most likely, you will get better performance by processing your regular expressions directly in Java, unless you have very large data to query against which may serve to mitigate the startup costs of invoking a separate process.

    Recommended steps:

    • Implement your solution in Java first.
    • If the Java solution is too slow for your needs, and the regular expression portion is the bottleneck, then explore other options.
    • To execute Perl, Runtime.exec or Process would work fine, just be sure to run the necessary threads to drain STDOUT and STDERR.

提交回复
热议问题