首页 \ 问答 \ 什么会使单个任务执行程序停止处理任务?(what would make a single task executor stop processing tasks?)

什么会使单个任务执行程序停止处理任务?(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 calling Executors.newSingleThreadExecutor(). This ExecutorService 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 with OutOfMemoryError 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
更新时间:2022-07-04 06:07

最满意答案

将正则表达式用于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, "");

相关问答

更多
  • 将正则表达式用于XML并不是一个好主意。 根据语言,您应该使用一些XML库。 在这种情况下,正则表达式非常简单: string s = "hello
    bye bye
    marco "; 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 ...
  • 使用XElement ,你有一个XML片段: var error = ""; var xe = XElement.Parse(error); var res = xe.Elements("MESSAGE") .Where(p => p.HasAttributes & ...
  • \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 ...
  • 根据正则表达式的文档, . 匹配除\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
  • 您可以在指定为MatchEvaluator回调的匿名方法中使用递增计数器。 (?<=…)是积极的看法; 它由正则表达式求值程序匹配,但不会被删除。 string input = "a "; int count = 0; string result = Regex.Replace(input, @"(?<=\ " android:label=label" + ...

相关文章

更多

最新问答

更多
  • 您如何使用git diff文件,并将其应用于同一存储库的副本的本地分支?(How do you take a git diff file, and apply it to a local branch that is a copy of the same repository?)
  • 将长浮点值剪切为2个小数点并复制到字符数组(Cut Long Float Value to 2 decimal points and copy to Character Array)
  • OctoberCMS侧边栏不呈现(OctoberCMS Sidebar not rendering)
  • 页面加载后对象是否有资格进行垃圾回收?(Are objects eligible for garbage collection after the page loads?)
  • codeigniter中的语言不能按预期工作(language in codeigniter doesn' t work as expected)
  • 在计算机拍照在哪里进入
  • 使用cin.get()从c ++中的输入流中丢弃不需要的字符(Using cin.get() to discard unwanted characters from the input stream in c++)
  • No for循环将在for循环中运行。(No for loop will run inside for loop. Testing for primes)
  • 单页应用程序:页面重新加载(Single Page Application: page reload)
  • 在循环中选择具有相似模式的列名称(Selecting Column Name With Similar Pattern in a Loop)
  • System.StackOverflow错误(System.StackOverflow error)
  • KnockoutJS未在嵌套模板上应用beforeRemove和afterAdd(KnockoutJS not applying beforeRemove and afterAdd on nested templates)
  • 散列包括方法和/或嵌套属性(Hash include methods and/or nested attributes)
  • android - 如何避免使用Samsung RFS文件系统延迟/冻结?(android - how to avoid lag/freezes with Samsung RFS filesystem?)
  • TensorFlow:基于索引列表创建新张量(TensorFlow: Create a new tensor based on list of indices)
  • 企业安全培训的各项内容
  • 错误:RPC失败;(error: RPC failed; curl transfer closed with outstanding read data remaining)
  • C#类名中允许哪些字符?(What characters are allowed in C# class name?)
  • NumPy:将int64值存储在np.array中并使用dtype float64并将其转换回整数是否安全?(NumPy: Is it safe to store an int64 value in an np.array with dtype float64 and later convert it back to integer?)
  • 注销后如何隐藏导航portlet?(How to hide navigation portlet after logout?)
  • 将多个行和可变行移动到列(moving multiple and variable rows to columns)
  • 提交表单时忽略基础href,而不使用Javascript(ignore base href when submitting form, without using Javascript)
  • 对setOnInfoWindowClickListener的意图(Intent on setOnInfoWindowClickListener)
  • Angular $资源不会改变方法(Angular $resource doesn't change method)
  • 在Angular 5中不是一个函数(is not a function in Angular 5)
  • 如何配置Composite C1以将.m和桌面作为同一站点提供服务(How to configure Composite C1 to serve .m and desktop as the same site)
  • 不适用:悬停在悬停时:在元素之前[复制](Don't apply :hover when hovering on :before element [duplicate])
  • 常见的python rpc和cli接口(Common python rpc and cli interface)
  • Mysql DB单个字段匹配多个其他字段(Mysql DB single field matching to multiple other fields)
  • 产品页面上的Magento Up出售对齐问题(Magento Up sell alignment issue on the products page)