This product is not supported for your selected Datadog site. ().
이 페이지는 아직 영어로 제공되지 않습니다. 번역 작업 중입니다. 현재 번역 프로젝트에 대한 질문이나 피드백이 있으신 경우 언제든지 연락주시기 바랍니다.
Metadata
ID:java-best-practices/replace-vector-with-list
Language: Java
Severity: Warning
Category: Best Practices
Description
Replace your Vector class usage with the newer java.util.ArrayList, unless you need expensive thread-safe operations.
Vector uses unnecessary synchronization, which can slow down single-threaded applications whereas ArrayList can perform better in such cases. In addition, it offers modern features which make the transition easy while retaining flexibility for thread safety when needed.
Non-Compliant Code Examples
publicclassFoo{voidbar(){Vectorvector1=newVector();// consider using java.util.List insteadVector<Integer>vector2=newVector<>();}}
Compliant Code Examples
packagecom.dd.logs.rum.sessionreducer;import staticio.vavr.API.Vector;importcom.dd.logs.launcher.Features;importcom.dd.logs.launcher.ModuleLauncher;importcom.dd.logs.rule_engine.reducer.main.ReducerWorkloadBundle;importcom.dd.logs.usage.UsageComponent;importcom.dd.logs.usage.UsageTrackerClientBundle;importcom.dd.logs.workload.assigner.AssignerClientBundle;importio.vavr.collection.Vector;importjava.util.List;publicclassMain{publicstaticvoidmain(String[]args){newModuleLauncher(List.of(newAssignerClientBundle(),newUsageTrackerClientBundle(UsageComponent.SESSIONIZATION),newReducerWorkloadBundle(newRumReducerWorkloadBundleParams())),// disconnected from mongoFeatures.builder().withKafka().build()).launchOrExit();Vector<String>x=returnSomeVavrVector();x.stdout();}privatestaticVector<String>returnSomeVavrVector(){returnVector();}}