class Test{
public static void main(String arg[]){
System.out.println("**MAIN METHOD");
System.out.println(Mno.VAL);//SOP(9090);
System.out.println(Mno.VAL+100);//SOP(9190);
}
}
class Mno{
final static int VAL=9090;
static{
System.out.println("**STATIC BLOCK OF Mno\t:"+VAL);
}
}
Run Code Online (Sandbox Code Playgroud)
我知道static在加载类时执行的块.但是在这种情况下,类中的实例变量Mno是final因为static块没有执行.
为什么会这样?如果我删除它final,它会工作正常吗?
首先分配哪个内存,static final变量或static块?
如果由于final访问修饰符而没有加载类,那么变量如何获取内存?
我有104k字符串值,其中89k是唯一的.我想检查一下该列表中是否存在字符串.
这是我的类及其保存所有这些记录的方法.
public class TestClass {
private static TestClass singletonObj = null;
private List<String> stringList= null;
public static synchronized TestClass getInstance() {
if(singletonObj == null) {
singletonObj = new TestClass();
}
return singletonObj;
}
public boolean isValidString(String token) {
if(stringList == null) {
init();
}
if(stringList != null && token != null && !token.isEmpty())
return stringList.contains(token.toLowerCase());
return false;
}
private init() {
stringList = new ArrayList<String>();
// put all 104k values in this data structure.
}
}
Run Code Online (Sandbox Code Playgroud)
我的应用程序尝试同时使用此isValidString()方法,每秒约20个请求.这工作正常但是当我尝试将数据结构更改为时 …
我很难解决这个问题。这是我的 Junit,我正在使用 spring 嵌入式 kafka。当我运行我的测试用例时,我遇到了奇怪的问题/异常。
@RunWith(SpringRunner.class)
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.NONE)
@ActiveProfiles("test")
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
@DirtiesContext
public class WatchListUpdateTest {
@ClassRule
public static KafkaEmbedded KAFKA = new KafkaEmbedded(1, true, "abc");
@BeforeClass
public static void startKafka() throws Exception {
String kafkaBootstrapServers = KAFKA.getBrokersAsString();
System.out.print("[Embedded Kafka Server:{}]" + kafkaBootstrapServers);
System.setProperty("kafka.consumer.bootstrap.servers", kafkaBootstrapServers);
System.setProperty("kafka.producer.bootstrap.servers", kafkaBootstrapServers);
}
@Autowired
ApplicationContext applicationContext;
private KafkaTestHelper helper = new KafkaTestHelper(KAFKA, "abc");
@Before
public void setUp() throws Exception {
helper.start(KAFKA.getPartitionsPerTopic());
}
@After
public void tearDown() throws Exception {
helper.stop();
}
@Test
public void testIng() …Run Code Online (Sandbox Code Playgroud) 我无法弄清楚设置<c:set>另一个JSP标记的结果的值.
这是我的代码:
<c:set var="desc" value="<c:choose>
<c:when test="${model.totalHits < 200}">${model.totalHits}</c:when>
<c:otherwise>${model.results.size()}</c:otherwise></c:choose>
positions at
<c:forEach items="${model.metaCompanies}" var='item' varStatus='status'>
${item} including ${model.metaDescsingleCompany}
</c:forEach>
related to ${model.querymetacompany}."/>
Run Code Online (Sandbox Code Playgroud)
获得此例外:
org.apache.jasper.JasperException: Unterminated <c:set tag
Run Code Online (Sandbox Code Playgroud)
难道我做错了什么 ?有没有其他方法可以实现这种情况?
如何用一条线实现这一目标?
我目前正在尝试这样做
示例:
{{"id" :"2", values: ["10","11", "12"]} , {"id" : "3", values : ["23"]}}
Run Code Online (Sandbox Code Playgroud)
至
{{"id" :"2","value": "10"},{"id": "2","value":"11"},
{"id" :"3","value":"23"} , {"id" : "2", "value":"12"}}
Run Code Online (Sandbox Code Playgroud)
我的java代码是
Map<Integer, List<Integer>> attrMap = new HashMap<>();
//getAllData() & item.getValues() both returns List
getAllData().forEach(item - > {
item.getValues().forEach(val - > {
attrMap.computeIfAbsent(item.getId(), (k) - >
new ArrayList < > ()).add(val.getValue());
});
});
Run Code Online (Sandbox Code Playgroud)
我怎么能只做一行?
java ×2
apache-kafka ×1
arraylist ×1
for-loop ×1
foreach ×1
hashset ×1
java-8 ×1
jsp ×1
jstl ×1
junit ×1
performance ×1
spring-boot ×1
static ×1