将Runnable实现到接口的抽象类(Abstract class that implements Runnable into interface)
如何将实现Runnable的抽象类重构为接口?
import com.codahale.metrics.health.HealthCheck; public abstract class ApplicationProcessor implements Runnable { public abstract HealthCheck getHealthCheck(); }
更新:以及如何在将来删除通用通配符类型的使用?
import io.dropwizard.lifecycle.Managed; import java.util.concurrent.Future; import com.codahale.metrics.health.HealthCheck; public class ManagedBean extends HealthCheck implements Managed { private final String name; private final ManagedThreadPool threadPool; private final ApplicationProcessor processor; private Future<?> future; // HERE sonarqube complains.. public ManagedBean( String name, ManagedThreadPool threadPool, ApplicationProcessor processor ) { this.name = name; this.threadPool = threadPool; this.processor = processor; } @Override public void start() throws Exception { future = threadPool.submit( processor ); } @Override public void stop() throws Exception { if ( !future.isDone() ) { future.cancel( true ); } } @Override protected Result check() throws Exception { return processor.getHealthCheck().execute(); } }
谢谢
How can I refactor an abstract class that implements Runnable into an interface?
import com.codahale.metrics.health.HealthCheck; public abstract class ApplicationProcessor implements Runnable { public abstract HealthCheck getHealthCheck(); }
UPDATE: And also how can I remove the usage of a generic wildcard type for the future?
import io.dropwizard.lifecycle.Managed; import java.util.concurrent.Future; import com.codahale.metrics.health.HealthCheck; public class ManagedBean extends HealthCheck implements Managed { private final String name; private final ManagedThreadPool threadPool; private final ApplicationProcessor processor; private Future<?> future; // HERE sonarqube complains.. public ManagedBean( String name, ManagedThreadPool threadPool, ApplicationProcessor processor ) { this.name = name; this.threadPool = threadPool; this.processor = processor; } @Override public void start() throws Exception { future = threadPool.submit( processor ); } @Override public void stop() throws Exception { if ( !future.isDone() ) { future.cancel( true ); } } @Override protected Result check() throws Exception { return processor.getHealthCheck().execute(); } }
Thanks
原文:https://stackoverflow.com/questions/35712338
更新时间:2024-02-16 06:02
最满意答案
注意 :我已经用非常小的一段数据测试过了。试试看,如果你卡住了,就让我知道。 我们会从那里拿走它。
假设我们的数据看起来像这样
现在我们运行这个代码
Sub Sample() Dim oSht As Worksheet Dim arr As Variant, FinalArr() As String Dim i As Long, j As Long, k As Long, LRow As Long Set oSht = ActiveSheet With oSht LRow = .Range("A" & .Rows.Count).End(xlUp).Row arr = .Range("A2:H" & LRow).Value i = Application.WorksheetFunction.CountA(.Range("G:H")) '~~> Defining the final output array ReDim Preserve FinalArr(1 To (LRow + i - 3), 1 To 6) k = 0 For i = LBound(arr) To UBound(arr) k = k + 1 FinalArr(k, 1) = arr(i, 1) FinalArr(k, 2) = arr(i, 2) FinalArr(k, 3) = arr(i, 3) FinalArr(k, 4) = arr(i, 4) FinalArr(k, 5) = arr(i, 5) If arr(i, 6) <> "" Then FinalArr(k, 6) = arr(i, 6) For j = 7 To 8 If arr(i, j) <> "" Then k = k + 1 FinalArr(k, 1) = arr(i, 1) FinalArr(k, 2) = arr(i, 2) FinalArr(k, 3) = arr(i, 3) FinalArr(k, 4) = arr(i, 4) FinalArr(k, 5) = arr(i, 5) FinalArr(k, 6) = arr(i, j) End If Next j Next i .Rows("2:" & .Rows.Count).Clear .Range("A2").Resize(UBound(FinalArr), 6).Value = FinalArr End With End Sub
产量
Note: I have tested this with very small piece of data.. Give it a try and if you are stuck then let me know. We will take it from there.
Let's say our data looks like this
Now we run this code
Sub Sample() Dim oSht As Worksheet Dim arr As Variant, FinalArr() As String Dim i As Long, j As Long, k As Long, LRow As Long Set oSht = ActiveSheet With oSht LRow = .Range("A" & .Rows.Count).End(xlUp).Row arr = .Range("A2:H" & LRow).Value i = Application.WorksheetFunction.CountA(.Range("G:H")) '~~> Defining the final output array ReDim Preserve FinalArr(1 To (LRow + i - 3), 1 To 6) k = 0 For i = LBound(arr) To UBound(arr) k = k + 1 FinalArr(k, 1) = arr(i, 1) FinalArr(k, 2) = arr(i, 2) FinalArr(k, 3) = arr(i, 3) FinalArr(k, 4) = arr(i, 4) FinalArr(k, 5) = arr(i, 5) If arr(i, 6) <> "" Then FinalArr(k, 6) = arr(i, 6) For j = 7 To 8 If arr(i, j) <> "" Then k = k + 1 FinalArr(k, 1) = arr(i, 1) FinalArr(k, 2) = arr(i, 2) FinalArr(k, 3) = arr(i, 3) FinalArr(k, 4) = arr(i, 4) FinalArr(k, 5) = arr(i, 5) FinalArr(k, 6) = arr(i, j) End If Next j Next i .Rows("2:" & .Rows.Count).Clear .Range("A2").Resize(UBound(FinalArr), 6).Value = FinalArr End With End Sub
Output
相关问答
更多-
Matlab内存不足 - 如何对矩阵元素进行就地操作?(Out of memory in Matlab - how to do in-place operation on matrix elements?)[2022-11-11]
有一些限制(进一步来自John引用的Loren块): 您的代码必须在函数内运行 您必须没有“数据”的其他别名 “别名”的事情既重要又可能很难做到。 MATLAB使用copy-on-write,这意味着当您调用函数时,您传递的参数不会立即重复,但如果您在函数中修改它,则可能会复制它。 例如,考虑一下 x = rand(100); y = myfcn(x); % with myfcn.m containing: function out = myfcn(in) in(1) = 3; out = in * ... -
注意 :我已经用非常小的一段数据测试过了。试试看,如果你卡住了,就让我知道。 我们会从那里拿走它。 假设我们的数据看起来像这样 现在我们运行这个代码 Sub Sample() Dim oSht As Worksheet Dim arr As Variant, FinalArr() As String Dim i As Long, j As Long, k As Long, LRow As Long Set oSht = ActiveSheet With oSht ...
-
没有足够的存储空间来完成此操作 - matlab(Not enough storage is available to complete this operation - matlab)[2023-05-14]
如果重启Matlab不是一个选项,“打包”功能应该有帮助。 否则你也可以在没有gui的情况下使用matlab,并为每个文件编写一个启动和matlab的shell脚本。 If restarting Matlab is not an option, the "pack" function should help. Otherwise you could also use matlab without the gui and write a shell script that starts and matlab ... -
正如您的帖子上的评论所示,此错误来自工作记忆的短缺。 每个Variant类型变量占用16个字节,这就是您的代码需要大量内存的原因。 因此,解决此问题的一种方法是增加计算机上的物理内存。 其他解决方案是按一定数量的行过滤数据。 Sub ProcessRows() Dim originalData() As Variant Dim maxRow as Long, currentRow as Long, incrementRow maxRow = ActiveSheet.Usedrang ...
-
在Pandas Dataframe slice上执行操作时出现内存错误(Memory Error when performing operation on Pandas Dataframe slice)[2023-06-29]
我使用的解决方案是将数据帧缩小: df = pd.read_hdf('madre_merge_sort32.h5') for i,d in enumerate(np.array_split(df, 10)): d.to_pickle(str(i)+".p") 然后我跑过那些腌制的mini-dfs并计算每个中的rmse: for fn in glob.glob("*.p"): # process df values df = pd.read_pickle(fn) df.re ... -
即使在x64上,cPython 2.4也可能存在大内存分配问题: $ python2.4 -c "'a' * (2**31-1)" Traceback (most recent call last): File "
", line 1, in ? MemoryError $ python2.5 -c "'a' * (2**31-1)" $ 更新到最近的python解释器(如cPython 2.7)以解决这些问题,并确保安装64位版本的解释器。 如果字符串具有非平凡的大小(即长于示例中的< ... -
除非分配给变量,否则不要使用圆括号。 Workbooks(theFile).SaveAs "Z:\test\vhb\" & newName, xlCSV You do not use parentheses unless you are assigning to a variable. Workbooks(theFile).SaveAs "Z:\test\vhb\" & newName, xlCSV
-
AFNetworking Memory(AFNetworking Memory)[2022-11-20]
在我的头顶 - 我看到你没有使用ARC。 AFHTTPRequestOperation *operation = [[AFHTTPRequestOperation alloc] initWithRequest:requestURL] 你在某处发布这个操作吗? [operation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject) { if (networ ... -
熊猫内存错误(Pandas memory error)[2022-01-07]
所以它需要我的64位Linux(32GB)内存,略低于2GB。 In [5]: def f(): df = DataFrame(np.random.randn(50000,300)) df.stack().reset_index(1) In [6]: %memit f() maximum of 1: 1791.054688 MB per loop 既然你没有指定。 这根本不适用于32位(因为你通常不能分配一个2GB的连续块),但是如果你有合理的交换/内存应该可以工作。 So ... -
如何使用Scipy进行内存有效的距离变换操作?(How can I use Scipy to do a memory efficient distance transform operation?)[2022-12-10]
您使用的是什么版本的Scipy? 在我正在运行的版本(0.12.0)中,没有out参数,因为有两个输出参数: distances和indices ,它们都可以用于输出。 如果提供了这些并且是ndarray或子类的实例,scipy将使用它们进行转换。 从文档: 距离:ndarray,可选 用于距离数组的输出,必须是float64类型。 指数:ndarray,可选 用于索引的输出,必须是int32类型。 请注意,文档中存在拼写错误,至少在0.12.0中: distance应该是distances 。 不幸的是, ...