什么会使单个任务执行程序停止处理任务?(what would make a single task executor stop processing tasks?)
我使用通过调用
Executors.newSingleThreadExecutor()
获得的java.util.concurrent.ExecutorService
。 这个ExecutorService
有时可以停止处理任务,即使它没有关闭并且继续接受新的任务而不会抛出异常。 最终,它会建立足够的队列,使我的应用程序关闭OutOfMemoryError
异常。该文档似乎表明,这个单线程执行程序应该通过启动一个新的工作线程来解决任务处理错误,以便替换已经死亡的线程。 我错过了什么吗?
I'm using a
java.util.concurrent.ExecutorService
that I obtained by callingExecutors.newSingleThreadExecutor()
. ThisExecutorService
can sometimes stop processing tasks, even though it has not been shutdown and continues to accept new tasks without throwing exceptions. Eventually, it builds up enough of a queue that my app shuts down withOutOfMemoryError
exceptions.The documentation seem to indicate that this single thread executor should survive task processing errors by firing up a new worker thread if necessary to replace one that has died. Am I missing something?
原文:https://stackoverflow.com/questions/344788
最满意答案
将正则表达式用于XML并不是一个好主意。 根据语言,您应该使用一些XML库。
在这种情况下,正则表达式非常简单:
string s = "hello <div>bye bye</div> marco <img />"; Regex rgx = new Regex("(<div>[^<]*</div>)|(<img */>)"); s = rgx.Replace(s, "");
It is not a good idea to use regex for XML. Depending on the language you should use some XML library.
In this case the regex is pretty simple, though:
string s = "hello <div>bye bye</div> marco <img />"; Regex rgx = new Regex("(<div>[^<]*</div>)|(<img */>)"); s = rgx.Replace(s, "");
相关问答
更多-
我如何在C#上执行此正则表达式?(How can I do this regex on C#?)[2022-05-03]
将正则表达式用于XML并不是一个好主意。 根据语言,您应该使用一些XML库。 在这种情况下,正则表达式非常简单: string s = "hellobye byemarco "; Regex rgx = new Regex("([^<]*)|()"); s = rgx.Replace(s, ""); It is not a good idea to use regex for X ... -
我无法重现上述行为 List
Input = new List () { "AAA", "BB", "AAA+15d", "BB-205w" }; string Pattern = @"^(AAA|BB)([+-]\d+[dw])*$"; foreach (string item in Input) { Console.WriteLine(Regex.IsMatch(item, Pattern)); } 结果: True True True True i ca ... -
基于Damien_The_Unbeliever的链接,我假设你的模式匹配一个文字* ,14个任意字符,然后是一个文字8 。 那么这将是你的正则表达式: @"^\*.{14}8$" 请注意. 通常不会匹配换行符。 如果您需要它,请设置SingleLline选项。 Match match = Regex.Match(input, @"^\*.{14}8$", RegexOptions.Singleline) if (match.Success) { // string has valid forma ...
-
你不需要放任何东西。 正则表达式允许给定字符串的部分匹配(除非指定诸如^和$锚)。 Regex r = new Regex(@"^Type / Subtype: (\d+) / (\d+)"); string arg = "Type / Subtype: 001 / 002 Additional pointless information that we don't need"; Match match = r.Match(arg); if (match.Success) { string num1 ...
-
只需从你的正则表达式中删除周围/ ,在.NET中不需要它。 可以使用Regex构造函数的RegexOptions.IgnoreCase第二个参数指定不区分大小写。 Regex rgx = new Regex(@"^[A-Z]{6}\d{2}[A-Z]\d{2}[A-Z]\d{3}[A-Z]$", RegexOptions.IgnoreCase); Just remove surrounding / from your regex, there is no need for it in .NET. Case ...
-
正则表达式在C#中不匹配(Regex not matching in C#)[2022-06-17]
使用XElement ,你有一个XML片段: var error = " "; var xe = XElement.Parse(error); var res = xe.Elements("MESSAGE") .Where(p => p.HasAttributes & ... -
C#正则表达式和美元符号(C# regex and dollar sign)[2023-04-27]
\b匹配字母数字字符和非字母数字字符 - 它与$和# ,空格或其他字符不匹配。 你可能想完全放弃它: @"(\$)[A-Fa-f\d]+\b" 如果你不希望模式与之前的字母数字字符匹配,你可以在它之前添加\B (所以#$00和a $00匹配,但a$00 )。 你也可以更挑剔,并禁止只有某些字符: @"(?<=[\w$])(\$)[A-Fa-f\d]+\b" 另见: 字边界 \b matches between an alphanumeric character and a non-alphanumeri ... -
为什么正则表达式挂在C#(Why does Regex hang in C#)[2023-07-20]
根据正则表达式的文档, . 匹配除\n之外的任何单个字符 。 这意味着. (与Java(默认模式),JavaScript等中的\r不匹配)与.NET中的\r匹配。 你的正则表达式有效地允许2个分支用于相同的字符\r 。 输入中的\r越多,运行正则表达式所需的时间就越长。 在输入失败时,它将根据输入中的\r的数量导致指数复杂性。 请注意,regexpal是一个JavaScript正则表达式测试程序,如上所述. 在JavaScript中排除\r , \n (以及一些其他行分隔符)。 由于它们匹配的内容没有重叠, ... -
尝试这个 ^[+]?[0-9]+$或^\+?\d+$ 说明: ^断言字符串开头的位置 \+匹配字符+ \d匹配一个数字[0-9] $断言字符串末尾的位置 try this ^[+]?[0-9]+$ or ^\+?\d+$ Explanation: ^ assert position at start of the string \+ matches the character + \d match a digit [0-9] $ assert position at end of the string
-
C#枚举正则表达式匹配(C# Enumerate Regex Matches)[2022-09-29]
您可以在指定为MatchEvaluator回调的匿名方法中使用递增计数器。 (?<=…)是积极的看法; 它由正则表达式求值程序匹配,但不会被删除。 string input = "a"; int count = 0; string result = Regex.Replace(input, @"(?<=\ " android:label=label" + ...