gpt4 book ai didi

java - 实体 save() 方法挂起,没有错误

转载 作者:行者123 更新时间:2023-11-29 02:12:41 24 4
gpt4 key购买 nike

我遇到一个问题,我的简单 AGI 应用程序在保存/更新实体时挂起并且没有抛出任何错误。从存储库中选择查询/方法按预期工作,没有任何错误。我将 Spring Boot 与 Spring Data JPA 一起使用,它会持久保存到 MYSQL 数据库。

订阅者.java :

package com.newcom.ncivr.model;

import org.joda.time.DateTime;
import org.joda.time.DateTimeZone;
import javax.persistence.*;

@Entity @Table(name = "subscribers")
public class Subscriber{

@Id
@GeneratedValue(strategy=GenerationType.IDENTITY)
private int Id;
private String msisdn;
private String subscriptionName;
@Column(columnDefinition = "DATETIME")
private DateTime lastRenewal;
private String status;

public Subscriber() {
}

public Subscriber(String msisdn, String subscriptionName) {
this.msisdn = msisdn;
this.subscriptionName = subscriptionName;
this.lastRenewal = DateTime.now(DateTimeZone.UTC).minusDays(1);
this.status = "ACTIVE";
}

//POJO Getters and Setters Excluded from Sample

}

SubscriberRepository.java :

package com.newcom.ncivr.repository;

import com.newcom.ncivr.model.Subscriber;
import org.springframework.data.repository.CrudRepository;
import org.springframework.stereotype.Repository;

@Repository
public interface SubscriberRepository extends CrudRepository<Subscriber,Integer>{
Subscriber findFirstByMsisdnAndSubscriptionNameAndStatus(String msisdn, String subscriptionName, String status);
}

IvrAgi.java :

package com.newcom.ncivr.agi;

import com.newcom.ncivr.model.Subscriber;
import com.newcom.ncivr.repository.SubscriberRepository;
import org.asteriskjava.fastagi.*;
import org.joda.time.DateTime;
import org.joda.time.DateTimeZone;
import org.joda.time.format.DateTimeFormat;
import org.joda.time.format.DateTimeFormatter;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;


public class IvrAgi extends BaseAgiScript {

private Logger log = LoggerFactory.getLogger(IvrAgi.class);

@Autowired
SubscriberRepository subscriberRepository;

public void service(AgiRequest request, AgiChannel channel) throws AgiException {

log.info("********** Agi Script Started. **************");
// Answer the channel...
answer();
log.info("Caller ID: "+request.getCallerIdNumber());
mainMenu(request);
log.info("********** Agi Script Completed. **************");

}

public void mainMenu(AgiRequest request) throws AgiException {
try {

while (true) {

String data = getData("ivr_main_menu");

log.info("User Input : " + data);

if (data.equals("1")) {
System.out.println(request.getCallerIdNumber() + ": User Selected 1");
streamFile("ivr_opt_one");
log.info(request.getCallerIdNumber() + ": User Selected 1");

try {
Subscriber subscriber = subscriberRepository.findFirstByMsisdnAndSubscriptionNameAndStatus(request.getCallerIdNumber(),"NEWS", "ACTIVE");

if(subscriber != null){
log.info("Id --->" + subscriber.toString());

subscriber.setLastRenewal(DateTime.now(DateTimeZone.UTC));
subscriber = subscriberRepository.save(subscriber);

log.info("Updated Entity --> " + subscriber.toString());
}else{
log.info("User is NOT Subscribed to NEWS");
}

}catch (Exception e){
e.printStackTrace();
}

hangup();
}else{
continue;
}
}

} catch (Throwable e) {
e.printStackTrace();
}
}
}

主要应用:

package com.newcom.ncivr;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.ImportResource;

@SpringBootApplication
@ImportResource("classpath:/asterisk/asterisk-config.xml")
public class IvrApplication {
@Autowired
public static void main(String[] args) {
SpringApplication.run(IvrApplication.class, args);
}
}

asterisk-config.xml(将 Asterisk AGI 映射到 Spring Boot 服务):

<?xml version="1.0" encoding="UTF-8" ?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.1.xsd">

<bean id="agiServer" class="org.asteriskjava.fastagi.DefaultAgiServer"
init-method="startup" destroy-method="shutdown">
<!--<property name="port" value="1111"/>-->
<property name="mappingStrategy" ref="mappingStrategy"/>
</bean>

<bean id="vanivr" class="com.newcom.ncivr.agi.IvrAgi">
</bean>

<bean id="mappingStrategy" class="org.asteriskjava.fastagi.SimpleMappingStrategy">
<property name="mappings">
<map>
<entry key="vanivr.agi" value-ref="vanivr"/>
</map>
</property>
</bean>

</beans>

应用程序属性:

#Database connection settings
spring.datasource.url=jdbc:mysql://localhost:3306/ncivr?useSSL=false
spring.datasource.username=root
spring.datasource.password=
spring.jpa.database=MYSQL
spring.jpa.show-sql=true
spring.jpa.hibernate.ddl-auto=update
spring.jpa.hibernate.naming.strategy=org.hibernate.cfg.ImprovedNamingStrategy
spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.MySQL5Dialect
spring.jpa.properties.jadira.usertype.autoRegisterUserTypes = true
logging.level.org.hibernate.SQL=DEBUG
logging.level.org.hibernate.type.descriptor.sql.BasicBinder=TRACE
spring.jpa.properties.hibernate.show_sql=false
spring.jpa.properties.hibernate.use_sql_comments=true
spring.jpa.properties.hibernate.format_sql=true
spring.jpa.properties.hibernate.type=trace
logging.level.org.hibernate=TRACE
debug=true

最佳答案

我把相关的堆栈跟踪放在下面的转储中。

有一个线程 BLOCKED,它正在等待锁定 <0x0000000081cc7448>。如果您搜索线程转储,您会在我在下面包含的另一个线程中找到第二次提到 0000000081cc7448

该线程名为 restartedMain,它似乎与监视文件并在文件更改时重新启动应用程序的 Boot Dev Tools 有关。例如,参见问题 SpringBoot app starts multiple times and disconnects from logstash和评论。

我建议您删除/禁用开发工具,因为它们似乎与问题有关。

"AJ DaemonPool-1.1" #258 daemon prio=5 os_prio=0 tid=0x000000001e067800 nid=0x4c0c waiting for monitor entry [0x000000002c75e000]
java.lang.Thread.State: BLOCKED (on object monitor)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:187)
- waiting to lock <0x0000000081cc7448> (a java.util.concurrent.ConcurrentHashMap)
at org.springframework.beans.factory.support.AbstractBeanFactory.isTypeMatch(AbstractBeanFactory.java:486)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.doGetBeanNamesForType(DefaultListableBeanFactory.java:432)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBeanNamesForType(DefaultListableBeanFactory.java:403)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBeanNamesForType(DefaultListableBeanFactory.java:389)
at org.springframework.beans.factory.BeanFactoryUtils.beanNamesForTypeIncludingAncestors(BeanFactoryUtils.java:177)
at org.springframework.beans.factory.annotation.BeanFactoryAnnotationUtils.qualifiedBeanOfType(BeanFactoryAnnotationUtils.java:89)
at org.springframework.beans.factory.annotation.BeanFactoryAnnotationUtils.qualifiedBeanOfType(BeanFactoryAnnotationUtils.java:66)
at org.springframework.transaction.interceptor.TransactionAspectSupport.determineQualifiedTransactionManager(TransactionAspectSupport.java:382)
at org.springframework.transaction.interceptor.TransactionAspectSupport.determineTransactionManager(TransactionAspectSupport.java:363)
at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:272)
at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:96)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
at org.springframework.dao.support.PersistenceExceptionTranslationInterceptor.invoke(PersistenceExceptionTranslationInterceptor.java:136)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
at org.springframework.data.jpa.repository.support.CrudMethodMetadataPostProcessor$CrudMethodMetadataPopulatingMethodInterceptor.invoke(CrudMethodMetadataPostProcessor.java:133)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:92)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
at org.springframework.data.repository.core.support.SurroundingTransactionDetectorMethodInterceptor.invoke(SurroundingTransactionDetectorMethodInterceptor.java:57)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:213)
at com.sun.proxy.$Proxy70.save(Unknown Source)
at com.newcom.ncivr.agi.VanuatuIvrAgi.mainMenuOptOne(VanuatuIvrAgi.java:109)
at com.newcom.ncivr.agi.VanuatuIvrAgi.mainMenu(VanuatuIvrAgi.java:56)
at com.newcom.ncivr.agi.VanuatuIvrAgi.service(VanuatuIvrAgi.java:38)
at com.newcom.ncivr.agi.VanuatuIvrAgi$$FastClassBySpringCGLIB$$1e77fb85.invoke(<generated>)
at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:204)
at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:669)
at com.newcom.ncivr.agi.VanuatuIvrAgi$$EnhancerBySpringCGLIB$$f6639040.service(<generated>)
at org.asteriskjava.fastagi.internal.AgiConnectionHandler.runScript(AgiConnectionHandler.java:165)
at org.asteriskjava.fastagi.internal.AgiConnectionHandler.run(AgiConnectionHandler.java:137)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at java.lang.Thread.run(Thread.java:748)


"restartedMain" #26 prio=5 os_prio=0 tid=0x000000001c4dc000 nid=0xf9c runnable [0x000000001de5d000]
java.lang.Thread.State: RUNNABLE
at java.net.DualStackPlainSocketImpl.accept0(Native Method)
at java.net.DualStackPlainSocketImpl.socketAccept(DualStackPlainSocketImpl.java:131)
at java.net.AbstractPlainSocketImpl.accept(AbstractPlainSocketImpl.java:409)
at java.net.PlainSocketImpl.accept(PlainSocketImpl.java:199)
- locked <0x00000000826ab858> (a java.net.SocksSocketImpl)
at java.net.ServerSocket.implAccept(ServerSocket.java:545)
at java.net.ServerSocket.accept(ServerSocket.java:513)
at org.asteriskjava.util.internal.ServerSocketFacadeImpl.accept(ServerSocketFacadeImpl.java:49)
at org.asteriskjava.fastagi.DefaultAgiServer.startup(DefaultAgiServer.java:312)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeCustomInitMethod(AbstractAutowireCapableBeanFactory.java:1758)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1695)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1624)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:555)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:483)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
- locked <0x0000000081cc7448> (a java.util.concurrent.ConcurrentHashMap)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:761)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:867)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:543)
- locked <0x0000000081cd9e08> (a java.lang.Object)
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:693)
at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:360)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:303)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1118)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1107)
at com.newcom.ncivr.NcivrApplication.main(NcivrApplication.java:13)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.springframework.boot.devtools.restart.RestartLauncher.run(RestartLauncher.java:49)

更新

从您的新 Thread dump 来看,如果没有 Boot Dev Tools 的帮助,这个 AGI 东西就会遇到麻烦。阻塞线程看起来与上面发布的非常相似。它正在尝试通过调用 DefaultAgiServer.startup 连接到某个服务器。不确定那里出了什么问题,但也许它会在很长一段时间后产生一些日志或失败并出现一个有意义的完整错误,或者你可以调试它?也许只是错误的连接信息?

我找到了这个 link在谷歌搜索方法调用时。

关于java - 实体 save() 方法挂起,没有错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47562447/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com